Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017 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 | #include "GrTextureOp.h" |
| 9 | #include "GrAppliedClip.h" |
Brian Salomon | 336ce7b | 2017-09-08 08:23:58 -0400 | [diff] [blame] | 10 | #include "GrCaps.h" |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 11 | #include "GrDrawOpTest.h" |
| 12 | #include "GrGeometryProcessor.h" |
| 13 | #include "GrMeshDrawOp.h" |
| 14 | #include "GrOpFlushState.h" |
| 15 | #include "GrQuad.h" |
| 16 | #include "GrResourceProvider.h" |
| 17 | #include "GrShaderCaps.h" |
| 18 | #include "GrTexture.h" |
Brian Salomon | 336ce7b | 2017-09-08 08:23:58 -0400 | [diff] [blame] | 19 | #include "GrTexturePriv.h" |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 20 | #include "GrTextureProxy.h" |
| 21 | #include "SkGr.h" |
Brian Salomon | 336ce7b | 2017-09-08 08:23:58 -0400 | [diff] [blame] | 22 | #include "SkMathPriv.h" |
Brian Salomon | a33b67c | 2018-05-17 10:42:14 -0400 | [diff] [blame] | 23 | #include "SkMatrixPriv.h" |
Brian Salomon | b5ef1f9 | 2018-01-11 11:46:21 -0500 | [diff] [blame] | 24 | #include "SkPoint.h" |
| 25 | #include "SkPoint3.h" |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 26 | #include "glsl/GrGLSLColorSpaceXformHelper.h" |
Brian Salomon | b5ef1f9 | 2018-01-11 11:46:21 -0500 | [diff] [blame] | 27 | #include "glsl/GrGLSLFragmentShaderBuilder.h" |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 28 | #include "glsl/GrGLSLGeometryProcessor.h" |
| 29 | #include "glsl/GrGLSLVarying.h" |
Brian Salomon | b5ef1f9 | 2018-01-11 11:46:21 -0500 | [diff] [blame] | 30 | #include "glsl/GrGLSLVertexGeoBuilder.h" |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 31 | |
| 32 | namespace { |
| 33 | |
Brian Salomon | 17031a7 | 2018-05-22 14:14:07 -0400 | [diff] [blame] | 34 | enum class MultiTexture : bool { kNo = false, kYes = true }; |
| 35 | |
Brian Salomon | b80ffee | 2018-05-23 16:39:39 -0400 | [diff] [blame] | 36 | enum class Domain : bool { kNo = false, kYes = true }; |
| 37 | |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 38 | /** |
| 39 | * Geometry Processor that draws a texture modulated by a vertex color (though, this is meant to be |
| 40 | * the same value across all vertices of a quad and uses flat interpolation when available). This is |
| 41 | * used by TextureOp below. |
| 42 | */ |
| 43 | class TextureGeometryProcessor : public GrGeometryProcessor { |
| 44 | public: |
Brian Salomon | 17031a7 | 2018-05-22 14:14:07 -0400 | [diff] [blame] | 45 | template <typename Pos> struct VertexCommon { |
| 46 | using Position = Pos; |
| 47 | Position fPosition; |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 48 | GrColor fColor; |
Brian Salomon | 17031a7 | 2018-05-22 14:14:07 -0400 | [diff] [blame] | 49 | SkPoint fTextureCoords; |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 50 | }; |
Brian Salomon | 17031a7 | 2018-05-22 14:14:07 -0400 | [diff] [blame] | 51 | |
| 52 | template <typename Pos, MultiTexture MT> struct OptionalMultiTextureVertex; |
| 53 | template <typename Pos> |
| 54 | struct OptionalMultiTextureVertex<Pos, MultiTexture::kNo> : VertexCommon<Pos> { |
| 55 | static constexpr MultiTexture kMultiTexture = MultiTexture::kNo; |
Brian Salomon | b5ef1f9 | 2018-01-11 11:46:21 -0500 | [diff] [blame] | 56 | }; |
Brian Salomon | 17031a7 | 2018-05-22 14:14:07 -0400 | [diff] [blame] | 57 | template <typename Pos> |
| 58 | struct OptionalMultiTextureVertex<Pos, MultiTexture::kYes> : VertexCommon<Pos> { |
| 59 | static constexpr MultiTexture kMultiTexture = MultiTexture::kYes; |
Brian Salomon | 336ce7b | 2017-09-08 08:23:58 -0400 | [diff] [blame] | 60 | int fTextureIdx; |
Brian Salomon | 336ce7b | 2017-09-08 08:23:58 -0400 | [diff] [blame] | 61 | }; |
Brian Salomon | 17031a7 | 2018-05-22 14:14:07 -0400 | [diff] [blame] | 62 | |
Brian Salomon | b80ffee | 2018-05-23 16:39:39 -0400 | [diff] [blame] | 63 | template <typename Pos, MultiTexture MT, Domain D> struct OptionalDomainVertex; |
Brian Salomon | 17031a7 | 2018-05-22 14:14:07 -0400 | [diff] [blame] | 64 | template <typename Pos, MultiTexture MT> |
Brian Salomon | b80ffee | 2018-05-23 16:39:39 -0400 | [diff] [blame] | 65 | struct OptionalDomainVertex<Pos, MT, Domain::kNo> : OptionalMultiTextureVertex<Pos, MT> { |
| 66 | static constexpr Domain kDomain = Domain::kNo; |
Brian Salomon | a0047bc | 2018-05-23 16:39:39 -0400 | [diff] [blame] | 67 | }; |
Stephen White | 633f20e | 2018-05-26 18:07:27 +0000 | [diff] [blame] | 68 | template <typename Pos, MultiTexture MT> |
Brian Salomon | b80ffee | 2018-05-23 16:39:39 -0400 | [diff] [blame] | 69 | struct OptionalDomainVertex<Pos, MT, Domain::kYes> : OptionalMultiTextureVertex<Pos, MT> { |
| 70 | static constexpr Domain kDomain = Domain::kYes; |
| 71 | SkRect fTextureDomain; |
| 72 | }; |
| 73 | |
| 74 | template <typename Pos, MultiTexture MT, Domain D, GrAA> struct OptionalAAVertex; |
| 75 | template <typename Pos, MultiTexture MT, Domain D> |
| 76 | struct OptionalAAVertex<Pos, MT, D, GrAA::kNo> : OptionalDomainVertex<Pos, MT, D> { |
| 77 | static constexpr GrAA kAA = GrAA::kNo; |
| 78 | }; |
| 79 | template <typename Pos, MultiTexture MT, Domain D> |
| 80 | struct OptionalAAVertex<Pos, MT, D, GrAA::kYes> : OptionalDomainVertex<Pos, MT, D> { |
Brian Salomon | be3c1d2 | 2018-05-21 12:54:39 -0400 | [diff] [blame] | 81 | static constexpr GrAA kAA = GrAA::kYes; |
Brian Salomon | b5ef1f9 | 2018-01-11 11:46:21 -0500 | [diff] [blame] | 82 | SkPoint3 fEdges[4]; |
Brian Salomon | b5ef1f9 | 2018-01-11 11:46:21 -0500 | [diff] [blame] | 83 | }; |
Brian Salomon | 336ce7b | 2017-09-08 08:23:58 -0400 | [diff] [blame] | 84 | |
Brian Salomon | b80ffee | 2018-05-23 16:39:39 -0400 | [diff] [blame] | 85 | template <typename Pos, MultiTexture MT, Domain D, GrAA AA> |
| 86 | using Vertex = OptionalAAVertex<Pos, MT, D, AA>; |
Brian Salomon | 17031a7 | 2018-05-22 14:14:07 -0400 | [diff] [blame] | 87 | |
Brian Salomon | 336ce7b | 2017-09-08 08:23:58 -0400 | [diff] [blame] | 88 | // Maximum number of textures supported by this op. Must also be checked against the caps |
| 89 | // limit. These numbers were based on some limited experiments on a HP Z840 and Pixel XL 2016 |
| 90 | // and could probably use more tuning. |
| 91 | #ifdef SK_BUILD_FOR_ANDROID |
| 92 | static constexpr int kMaxTextures = 4; |
| 93 | #else |
| 94 | static constexpr int kMaxTextures = 8; |
| 95 | #endif |
| 96 | |
Brian Salomon | 0b4d8aa | 2017-10-11 15:34:27 -0400 | [diff] [blame] | 97 | static int SupportsMultitexture(const GrShaderCaps& caps) { |
Brian Salomon | 762d5e7 | 2017-12-01 10:25:08 -0500 | [diff] [blame] | 98 | return caps.integerSupport() && caps.maxFragmentSamplers() > 1; |
Brian Salomon | 0b4d8aa | 2017-10-11 15:34:27 -0400 | [diff] [blame] | 99 | } |
Brian Salomon | 336ce7b | 2017-09-08 08:23:58 -0400 | [diff] [blame] | 100 | |
| 101 | static sk_sp<GrGeometryProcessor> Make(sk_sp<GrTextureProxy> proxies[], int proxyCnt, |
Brian Salomon | 485b8c6 | 2018-01-12 15:11:06 -0500 | [diff] [blame] | 102 | sk_sp<GrColorSpaceXform> csxf, bool coverageAA, |
Brian Salomon | b80ffee | 2018-05-23 16:39:39 -0400 | [diff] [blame] | 103 | bool perspective, Domain domain, |
| 104 | const GrSamplerState::Filter filters[], |
Brian Salomon | 336ce7b | 2017-09-08 08:23:58 -0400 | [diff] [blame] | 105 | const GrShaderCaps& caps) { |
| 106 | // We use placement new to avoid always allocating space for kMaxTextures TextureSampler |
| 107 | // instances. |
| 108 | int samplerCnt = NumSamplersToUse(proxyCnt, caps); |
| 109 | size_t size = sizeof(TextureGeometryProcessor) + sizeof(TextureSampler) * (samplerCnt - 1); |
| 110 | void* mem = GrGeometryProcessor::operator new(size); |
Brian Salomon | be3c1d2 | 2018-05-21 12:54:39 -0400 | [diff] [blame] | 111 | return sk_sp<TextureGeometryProcessor>( |
| 112 | new (mem) TextureGeometryProcessor(proxies, proxyCnt, samplerCnt, std::move(csxf), |
Brian Salomon | b80ffee | 2018-05-23 16:39:39 -0400 | [diff] [blame] | 113 | coverageAA, perspective, domain, filters, caps)); |
Brian Salomon | 336ce7b | 2017-09-08 08:23:58 -0400 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | ~TextureGeometryProcessor() override { |
| 117 | int cnt = this->numTextureSamplers(); |
| 118 | for (int i = 1; i < cnt; ++i) { |
| 119 | fSamplers[i].~TextureSampler(); |
| 120 | } |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | const char* name() const override { return "TextureGeometryProcessor"; } |
| 124 | |
| 125 | void getGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder* b) const override { |
| 126 | b->add32(GrColorSpaceXform::XformKey(fColorSpaceXform.get())); |
Brian Salomon | be3c1d2 | 2018-05-21 12:54:39 -0400 | [diff] [blame] | 127 | uint32_t x = this->usesCoverageEdgeAA() ? 0 : 1; |
| 128 | x |= kFloat3_GrVertexAttribType == fPositions.fType ? 0 : 2; |
Brian Salomon | b80ffee | 2018-05-23 16:39:39 -0400 | [diff] [blame] | 129 | x |= fDomain.isInitialized() ? 4 : 0; |
Brian Salomon | be3c1d2 | 2018-05-21 12:54:39 -0400 | [diff] [blame] | 130 | b->add32(x); |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | GrGLSLPrimitiveProcessor* createGLSLInstance(const GrShaderCaps& caps) const override { |
| 134 | class GLSLProcessor : public GrGLSLGeometryProcessor { |
| 135 | public: |
| 136 | void setData(const GrGLSLProgramDataManager& pdman, const GrPrimitiveProcessor& proc, |
| 137 | FPCoordTransformIter&& transformIter) override { |
| 138 | const auto& textureGP = proc.cast<TextureGeometryProcessor>(); |
| 139 | this->setTransformDataHelper(SkMatrix::I(), pdman, &transformIter); |
| 140 | if (fColorSpaceXformHelper.isValid()) { |
| 141 | fColorSpaceXformHelper.setData(pdman, textureGP.fColorSpaceXform.get()); |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | private: |
| 146 | void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override { |
Chris Dalton | 7b04631 | 2018-02-02 11:06:30 -0700 | [diff] [blame] | 147 | using Interpolation = GrGLSLVaryingHandler::Interpolation; |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 148 | const auto& textureGP = args.fGP.cast<TextureGeometryProcessor>(); |
| 149 | fColorSpaceXformHelper.emitCode( |
| 150 | args.fUniformHandler, textureGP.fColorSpaceXform.get()); |
Brian Salomon | be3c1d2 | 2018-05-21 12:54:39 -0400 | [diff] [blame] | 151 | if (kFloat2_GrVertexAttribType == textureGP.fPositions.fType) { |
| 152 | args.fVaryingHandler->setNoPerspective(); |
| 153 | } |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 154 | args.fVaryingHandler->emitAttributes(textureGP); |
Brian Salomon | be3c1d2 | 2018-05-21 12:54:39 -0400 | [diff] [blame] | 155 | gpArgs->fPositionVar = textureGP.fPositions.asShaderVar(); |
| 156 | |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 157 | this->emitTransforms(args.fVertBuilder, |
| 158 | args.fVaryingHandler, |
| 159 | args.fUniformHandler, |
Brian Salomon | 04460cc | 2017-12-06 14:47:42 -0500 | [diff] [blame] | 160 | textureGP.fTextureCoords.asShaderVar(), |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 161 | args.fFPCoordTransformHandler); |
Chris Dalton | 7b04631 | 2018-02-02 11:06:30 -0700 | [diff] [blame] | 162 | args.fVaryingHandler->addPassThroughAttribute(&textureGP.fColors, |
| 163 | args.fOutputColor, |
| 164 | Interpolation::kCanBeFlat); |
Ethan Nicholas | 8aa4569 | 2017-09-20 11:24:15 -0400 | [diff] [blame] | 165 | args.fFragBuilder->codeAppend("float2 texCoord;"); |
Chris Dalton | fdde34e | 2017-10-16 14:15:26 -0600 | [diff] [blame] | 166 | args.fVaryingHandler->addPassThroughAttribute(&textureGP.fTextureCoords, |
| 167 | "texCoord"); |
Brian Salomon | b80ffee | 2018-05-23 16:39:39 -0400 | [diff] [blame] | 168 | if (textureGP.fDomain.isInitialized()) { |
| 169 | args.fFragBuilder->codeAppend("float4 domain;"); |
| 170 | args.fVaryingHandler->addPassThroughAttribute( |
| 171 | &textureGP.fDomain, "domain", |
| 172 | GrGLSLVaryingHandler::Interpolation::kCanBeFlat); |
| 173 | args.fFragBuilder->codeAppend( |
| 174 | "texCoord = clamp(texCoord, domain.xy, domain.zw);"); |
| 175 | } |
Brian Salomon | 336ce7b | 2017-09-08 08:23:58 -0400 | [diff] [blame] | 176 | if (textureGP.numTextureSamplers() > 1) { |
Chris Dalton | 7b04631 | 2018-02-02 11:06:30 -0700 | [diff] [blame] | 177 | // If this changes to float, reconsider Interpolation::kMustBeFlat. |
| 178 | SkASSERT(kInt_GrVertexAttribType == textureGP.fTextureIdx.fType); |
Brian Salomon | 336ce7b | 2017-09-08 08:23:58 -0400 | [diff] [blame] | 179 | SkASSERT(args.fShaderCaps->integerSupport()); |
| 180 | args.fFragBuilder->codeAppend("int texIdx;"); |
Chris Dalton | 7b04631 | 2018-02-02 11:06:30 -0700 | [diff] [blame] | 181 | args.fVaryingHandler->addPassThroughAttribute(&textureGP.fTextureIdx, "texIdx", |
| 182 | Interpolation::kMustBeFlat); |
Brian Salomon | 336ce7b | 2017-09-08 08:23:58 -0400 | [diff] [blame] | 183 | args.fFragBuilder->codeAppend("switch (texIdx) {"); |
| 184 | for (int i = 0; i < textureGP.numTextureSamplers(); ++i) { |
| 185 | args.fFragBuilder->codeAppendf("case %d: %s = ", i, args.fOutputColor); |
| 186 | args.fFragBuilder->appendTextureLookupAndModulate(args.fOutputColor, |
| 187 | args.fTexSamplers[i], |
| 188 | "texCoord", |
Ethan Nicholas | 8aa4569 | 2017-09-20 11:24:15 -0400 | [diff] [blame] | 189 | kFloat2_GrSLType, |
Brian Salomon | 336ce7b | 2017-09-08 08:23:58 -0400 | [diff] [blame] | 190 | &fColorSpaceXformHelper); |
| 191 | args.fFragBuilder->codeAppend("; break;"); |
| 192 | } |
| 193 | args.fFragBuilder->codeAppend("}"); |
| 194 | } else { |
| 195 | args.fFragBuilder->codeAppendf("%s = ", args.fOutputColor); |
| 196 | args.fFragBuilder->appendTextureLookupAndModulate(args.fOutputColor, |
| 197 | args.fTexSamplers[0], |
| 198 | "texCoord", |
Ethan Nicholas | 8aa4569 | 2017-09-20 11:24:15 -0400 | [diff] [blame] | 199 | kFloat2_GrSLType, |
Brian Salomon | 336ce7b | 2017-09-08 08:23:58 -0400 | [diff] [blame] | 200 | &fColorSpaceXformHelper); |
| 201 | } |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 202 | args.fFragBuilder->codeAppend(";"); |
Brian Salomon | 485b8c6 | 2018-01-12 15:11:06 -0500 | [diff] [blame] | 203 | if (textureGP.usesCoverageEdgeAA()) { |
Brian Salomon | dba65f9 | 2018-01-22 08:43:38 -0500 | [diff] [blame] | 204 | const char* aaDistName = nullptr; |
Brian Salomon | be3c1d2 | 2018-05-21 12:54:39 -0400 | [diff] [blame] | 205 | bool mulByFragCoordW = false; |
| 206 | // When interpolation is inaccurate we perform the evaluation of the edge |
Brian Salomon | dba65f9 | 2018-01-22 08:43:38 -0500 | [diff] [blame] | 207 | // equations in the fragment shader rather than interpolating values computed |
| 208 | // in the vertex shader. |
| 209 | if (!args.fShaderCaps->interpolantsAreInaccurate()) { |
| 210 | GrGLSLVarying aaDistVarying(kFloat4_GrSLType, |
| 211 | GrGLSLVarying::Scope::kVertToFrag); |
Brian Salomon | be3c1d2 | 2018-05-21 12:54:39 -0400 | [diff] [blame] | 212 | if (kFloat3_GrVertexAttribType == textureGP.fPositions.fType) { |
| 213 | args.fVaryingHandler->addVarying("aaDists", &aaDistVarying); |
| 214 | // The distance from edge equation e to homogenous point p=sk_Position |
| 215 | // is e.x*p.x/p.wx + e.y*p.y/p.w + e.z. However, we want screen space |
| 216 | // interpolation of this distance. We can do this by multiplying the |
| 217 | // varying in the VS by p.w and then multiplying by sk_FragCoord.w in |
| 218 | // the FS. So we output e.x*p.x + e.y*p.y + e.z * p.w |
| 219 | args.fVertBuilder->codeAppendf( |
| 220 | R"(%s = float4(dot(aaEdge0, %s), dot(aaEdge1, %s), |
| 221 | dot(aaEdge2, %s), dot(aaEdge3, %s));)", |
| 222 | aaDistVarying.vsOut(), textureGP.fPositions.fName, |
| 223 | textureGP.fPositions.fName, textureGP.fPositions.fName, |
| 224 | textureGP.fPositions.fName); |
| 225 | mulByFragCoordW = true; |
| 226 | } else { |
| 227 | args.fVaryingHandler->addVarying("aaDists", &aaDistVarying); |
| 228 | args.fVertBuilder->codeAppendf( |
| 229 | R"(%s = float4(dot(aaEdge0.xy, %s.xy) + aaEdge0.z, |
| 230 | dot(aaEdge1.xy, %s.xy) + aaEdge1.z, |
| 231 | dot(aaEdge2.xy, %s.xy) + aaEdge2.z, |
| 232 | dot(aaEdge3.xy, %s.xy) + aaEdge3.z);)", |
| 233 | aaDistVarying.vsOut(), textureGP.fPositions.fName, |
| 234 | textureGP.fPositions.fName, textureGP.fPositions.fName, |
| 235 | textureGP.fPositions.fName); |
| 236 | } |
Brian Salomon | dba65f9 | 2018-01-22 08:43:38 -0500 | [diff] [blame] | 237 | aaDistName = aaDistVarying.fsIn(); |
| 238 | } else { |
| 239 | GrGLSLVarying aaEdgeVarying[4]{ |
| 240 | {kFloat3_GrSLType, GrGLSLVarying::Scope::kVertToFrag}, |
| 241 | {kFloat3_GrSLType, GrGLSLVarying::Scope::kVertToFrag}, |
| 242 | {kFloat3_GrSLType, GrGLSLVarying::Scope::kVertToFrag}, |
| 243 | {kFloat3_GrSLType, GrGLSLVarying::Scope::kVertToFrag} |
| 244 | }; |
| 245 | for (int i = 0; i < 4; ++i) { |
| 246 | SkString name; |
| 247 | name.printf("aaEdge%d", i); |
Brian Salomon | 7d982c6 | 2018-02-05 16:20:47 -0500 | [diff] [blame] | 248 | args.fVaryingHandler->addVarying(name.c_str(), &aaEdgeVarying[i], |
| 249 | Interpolation::kCanBeFlat); |
Brian Salomon | dba65f9 | 2018-01-22 08:43:38 -0500 | [diff] [blame] | 250 | args.fVertBuilder->codeAppendf( |
| 251 | "%s = aaEdge%d;", aaEdgeVarying[i].vsOut(), i); |
| 252 | } |
| 253 | args.fFragBuilder->codeAppendf( |
| 254 | R"(float4 aaDists = float4(dot(%s.xy, sk_FragCoord.xy) + %s.z, |
| 255 | dot(%s.xy, sk_FragCoord.xy) + %s.z, |
| 256 | dot(%s.xy, sk_FragCoord.xy) + %s.z, |
| 257 | dot(%s.xy, sk_FragCoord.xy) + %s.z);)", |
| 258 | aaEdgeVarying[0].fsIn(), aaEdgeVarying[0].fsIn(), |
| 259 | aaEdgeVarying[1].fsIn(), aaEdgeVarying[1].fsIn(), |
| 260 | aaEdgeVarying[2].fsIn(), aaEdgeVarying[2].fsIn(), |
| 261 | aaEdgeVarying[3].fsIn(), aaEdgeVarying[3].fsIn()); |
| 262 | aaDistName = "aaDists"; |
| 263 | } |
Brian Salomon | b5ef1f9 | 2018-01-11 11:46:21 -0500 | [diff] [blame] | 264 | args.fFragBuilder->codeAppendf( |
| 265 | "float mindist = min(min(%s.x, %s.y), min(%s.z, %s.w));", |
Brian Salomon | dba65f9 | 2018-01-22 08:43:38 -0500 | [diff] [blame] | 266 | aaDistName, aaDistName, aaDistName, aaDistName); |
Brian Salomon | be3c1d2 | 2018-05-21 12:54:39 -0400 | [diff] [blame] | 267 | if (mulByFragCoordW) { |
| 268 | args.fFragBuilder->codeAppend("mindist *= sk_FragCoord.w;"); |
| 269 | } |
Brian Salomon | b5ef1f9 | 2018-01-11 11:46:21 -0500 | [diff] [blame] | 270 | args.fFragBuilder->codeAppendf("%s = float4(clamp(mindist, 0, 1));", |
| 271 | args.fOutputCoverage); |
| 272 | } else { |
| 273 | args.fFragBuilder->codeAppendf("%s = float4(1);", args.fOutputCoverage); |
| 274 | } |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 275 | } |
| 276 | GrGLSLColorSpaceXformHelper fColorSpaceXformHelper; |
| 277 | }; |
| 278 | return new GLSLProcessor; |
| 279 | } |
| 280 | |
Brian Salomon | 485b8c6 | 2018-01-12 15:11:06 -0500 | [diff] [blame] | 281 | bool usesCoverageEdgeAA() const { return SkToBool(fAAEdges[0].isInitialized()); } |
Brian Salomon | b5ef1f9 | 2018-01-11 11:46:21 -0500 | [diff] [blame] | 282 | |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 283 | private: |
Brian Salomon | 336ce7b | 2017-09-08 08:23:58 -0400 | [diff] [blame] | 284 | // This exists to reduce the number of shaders generated. It does some rounding of sampler |
| 285 | // counts. |
| 286 | static int NumSamplersToUse(int numRealProxies, const GrShaderCaps& caps) { |
| 287 | SkASSERT(numRealProxies > 0 && numRealProxies <= kMaxTextures && |
| 288 | numRealProxies <= caps.maxFragmentSamplers()); |
| 289 | if (1 == numRealProxies) { |
| 290 | return 1; |
| 291 | } |
| 292 | if (numRealProxies <= 4) { |
| 293 | return 4; |
| 294 | } |
| 295 | // Round to the next power of 2 and then clamp to kMaxTextures and the max allowed by caps. |
| 296 | return SkTMin(SkNextPow2(numRealProxies), SkTMin(kMaxTextures, caps.maxFragmentSamplers())); |
| 297 | } |
| 298 | |
| 299 | TextureGeometryProcessor(sk_sp<GrTextureProxy> proxies[], int proxyCnt, int samplerCnt, |
Brian Salomon | be3c1d2 | 2018-05-21 12:54:39 -0400 | [diff] [blame] | 300 | sk_sp<GrColorSpaceXform> csxf, bool coverageAA, bool perspective, |
Brian Salomon | b80ffee | 2018-05-23 16:39:39 -0400 | [diff] [blame] | 301 | Domain domain, const GrSamplerState::Filter filters[], |
| 302 | const GrShaderCaps& caps) |
Brian Salomon | b5ef1f9 | 2018-01-11 11:46:21 -0500 | [diff] [blame] | 303 | : INHERITED(kTextureGeometryProcessor_ClassID), fColorSpaceXform(std::move(csxf)) { |
Brian Salomon | 336ce7b | 2017-09-08 08:23:58 -0400 | [diff] [blame] | 304 | SkASSERT(proxyCnt > 0 && samplerCnt >= proxyCnt); |
Brian Salomon | 336ce7b | 2017-09-08 08:23:58 -0400 | [diff] [blame] | 305 | fSamplers[0].reset(std::move(proxies[0]), filters[0]); |
| 306 | this->addTextureSampler(&fSamplers[0]); |
| 307 | for (int i = 1; i < proxyCnt; ++i) { |
| 308 | // This class has one sampler built in, the rest come from memory this processor was |
| 309 | // placement-newed into and so haven't been constructed. |
| 310 | new (&fSamplers[i]) TextureSampler(std::move(proxies[i]), filters[i]); |
| 311 | this->addTextureSampler(&fSamplers[i]); |
| 312 | } |
Brian Salomon | 30e1a5e | 2018-05-18 12:32:32 -0400 | [diff] [blame] | 313 | |
Brian Salomon | be3c1d2 | 2018-05-21 12:54:39 -0400 | [diff] [blame] | 314 | if (perspective) { |
| 315 | fPositions = this->addVertexAttrib("position", kFloat3_GrVertexAttribType); |
| 316 | } else { |
| 317 | fPositions = this->addVertexAttrib("position", kFloat2_GrVertexAttribType); |
| 318 | } |
Brian Salomon | 30e1a5e | 2018-05-18 12:32:32 -0400 | [diff] [blame] | 319 | fColors = this->addVertexAttrib("color", kUByte4_norm_GrVertexAttribType); |
Brian Salomon | 17031a7 | 2018-05-22 14:14:07 -0400 | [diff] [blame] | 320 | fTextureCoords = this->addVertexAttrib("textureCoords", kFloat2_GrVertexAttribType); |
Brian Salomon | 30e1a5e | 2018-05-18 12:32:32 -0400 | [diff] [blame] | 321 | |
Brian Salomon | 336ce7b | 2017-09-08 08:23:58 -0400 | [diff] [blame] | 322 | if (samplerCnt > 1) { |
| 323 | // Here we initialize any extra samplers by repeating the last one samplerCnt - proxyCnt |
| 324 | // times. |
| 325 | GrTextureProxy* dupeProxy = fSamplers[proxyCnt - 1].proxy(); |
| 326 | for (int i = proxyCnt; i < samplerCnt; ++i) { |
| 327 | new (&fSamplers[i]) TextureSampler(sk_ref_sp(dupeProxy), filters[proxyCnt - 1]); |
| 328 | this->addTextureSampler(&fSamplers[i]); |
| 329 | } |
| 330 | SkASSERT(caps.integerSupport()); |
| 331 | fTextureIdx = this->addVertexAttrib("textureIdx", kInt_GrVertexAttribType); |
| 332 | } |
Brian Salomon | b80ffee | 2018-05-23 16:39:39 -0400 | [diff] [blame] | 333 | if (domain == Domain::kYes) { |
| 334 | fDomain = this->addVertexAttrib("domain", kFloat4_GrVertexAttribType); |
| 335 | } |
Brian Salomon | 485b8c6 | 2018-01-12 15:11:06 -0500 | [diff] [blame] | 336 | if (coverageAA) { |
Brian Salomon | b5ef1f9 | 2018-01-11 11:46:21 -0500 | [diff] [blame] | 337 | fAAEdges[0] = this->addVertexAttrib("aaEdge0", kFloat3_GrVertexAttribType); |
| 338 | fAAEdges[1] = this->addVertexAttrib("aaEdge1", kFloat3_GrVertexAttribType); |
| 339 | fAAEdges[2] = this->addVertexAttrib("aaEdge2", kFloat3_GrVertexAttribType); |
| 340 | fAAEdges[3] = this->addVertexAttrib("aaEdge3", kFloat3_GrVertexAttribType); |
| 341 | } |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 342 | } |
| 343 | |
| 344 | Attribute fPositions; |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 345 | Attribute fColors; |
Brian Salomon | 30e1a5e | 2018-05-18 12:32:32 -0400 | [diff] [blame] | 346 | Attribute fTextureCoords; |
| 347 | Attribute fTextureIdx; |
Brian Salomon | b80ffee | 2018-05-23 16:39:39 -0400 | [diff] [blame] | 348 | Attribute fDomain; |
Brian Salomon | b5ef1f9 | 2018-01-11 11:46:21 -0500 | [diff] [blame] | 349 | Attribute fAAEdges[4]; |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 350 | sk_sp<GrColorSpaceXform> fColorSpaceXform; |
Brian Salomon | 336ce7b | 2017-09-08 08:23:58 -0400 | [diff] [blame] | 351 | TextureSampler fSamplers[1]; |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 352 | |
| 353 | typedef GrGeometryProcessor INHERITED; |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 354 | }; |
| 355 | |
Brian Salomon | 6872e94 | 2018-05-18 10:29:54 -0400 | [diff] [blame] | 356 | // This computes the four edge equations for a quad, then outsets them and computes a new quad |
| 357 | // as the intersection points of the outset edges. 'x' and 'y' contain the original points as input |
| 358 | // and the outset points as output. 'a', 'b', and 'c' are the edge equation coefficients on output. |
| 359 | static void compute_quad_edges_and_outset_vertices(Sk4f* x, Sk4f* y, Sk4f* a, Sk4f* b, Sk4f* c) { |
| 360 | static constexpr auto fma = SkNx_fma<4, float>; |
| 361 | // These rotate the points/edge values either clockwise or counterclockwise assuming tri strip |
| 362 | // order. |
| 363 | auto nextCW = [](const Sk4f& v) { return SkNx_shuffle<2, 0, 3, 1>(v); }; |
| 364 | auto nextCCW = [](const Sk4f& v) { return SkNx_shuffle<1, 3, 0, 2>(v); }; |
| 365 | |
| 366 | auto xnext = nextCCW(*x); |
| 367 | auto ynext = nextCCW(*y); |
| 368 | *a = ynext - *y; |
| 369 | *b = *x - xnext; |
| 370 | *c = fma(xnext, *y, -ynext * *x); |
| 371 | Sk4f invNormLengths = (*a * *a + *b * *b).rsqrt(); |
| 372 | // Make sure the edge equations have their normals facing into the quad in device space. |
| 373 | auto test = fma(*a, nextCW(*x), fma(*b, nextCW(*y), *c)); |
| 374 | if ((test < Sk4f(0)).anyTrue()) { |
| 375 | invNormLengths = -invNormLengths; |
| 376 | } |
| 377 | *a *= invNormLengths; |
| 378 | *b *= invNormLengths; |
| 379 | *c *= invNormLengths; |
| 380 | |
| 381 | // Here is the outset. This makes our edge equations compute coverage without requiring a |
| 382 | // half pixel offset and is also used to compute the bloated quad that will cover all |
| 383 | // pixels. |
| 384 | *c += Sk4f(0.5f); |
| 385 | |
| 386 | // Reverse the process to compute the points of the bloated quad from the edge equations. |
| 387 | // This time the inputs don't have 1s as their third coord and we want to homogenize rather |
| 388 | // than normalize. |
| 389 | auto anext = nextCW(*a); |
| 390 | auto bnext = nextCW(*b); |
| 391 | auto cnext = nextCW(*c); |
| 392 | *x = fma(bnext, *c, -*b * cnext); |
| 393 | *y = fma(*a, cnext, -anext * *c); |
| 394 | auto ic = (fma(anext, *b, -bnext * *a)).invert(); |
| 395 | *x *= ic; |
| 396 | *y *= ic; |
| 397 | } |
| 398 | |
Brian Salomon | b5ef1f9 | 2018-01-11 11:46:21 -0500 | [diff] [blame] | 399 | namespace { |
| 400 | // This is a class soley so it can be partially specialized (functions cannot be). |
Brian Salomon | 86c4001 | 2018-05-22 10:48:49 -0400 | [diff] [blame] | 401 | template <typename V, GrAA AA = V::kAA, typename Position = typename V::Position> |
Brian Salomon | be3c1d2 | 2018-05-21 12:54:39 -0400 | [diff] [blame] | 402 | class VertexAAHandler; |
Brian Salomon | b5ef1f9 | 2018-01-11 11:46:21 -0500 | [diff] [blame] | 403 | |
Brian Salomon | 86c4001 | 2018-05-22 10:48:49 -0400 | [diff] [blame] | 404 | template<typename V> class VertexAAHandler<V, GrAA::kNo, SkPoint> { |
Brian Salomon | b5ef1f9 | 2018-01-11 11:46:21 -0500 | [diff] [blame] | 405 | public: |
Brian Salomon | 86c4001 | 2018-05-22 10:48:49 -0400 | [diff] [blame] | 406 | static void AssignPositionsAndTexCoords(V* vertices, const GrPerspQuad& quad, |
Brian Salomon | b5ef1f9 | 2018-01-11 11:46:21 -0500 | [diff] [blame] | 407 | const SkRect& texRect) { |
Brian Salomon | be3c1d2 | 2018-05-21 12:54:39 -0400 | [diff] [blame] | 408 | SkASSERT((quad.w4f() == Sk4f(1.f)).allTrue()); |
Brian Salomon | 86c4001 | 2018-05-22 10:48:49 -0400 | [diff] [blame] | 409 | SkPointPriv::SetRectTriStrip(&vertices[0].fTextureCoords, texRect, sizeof(V)); |
Brian Salomon | be3c1d2 | 2018-05-21 12:54:39 -0400 | [diff] [blame] | 410 | for (int i = 0; i < 4; ++i) { |
| 411 | vertices[i].fPosition = {quad.x(i), quad.y(i)}; |
| 412 | } |
Brian Salomon | b5ef1f9 | 2018-01-11 11:46:21 -0500 | [diff] [blame] | 413 | } |
| 414 | }; |
| 415 | |
Brian Salomon | 86c4001 | 2018-05-22 10:48:49 -0400 | [diff] [blame] | 416 | template<typename V> class VertexAAHandler<V, GrAA::kNo, SkPoint3> { |
Brian Salomon | b5ef1f9 | 2018-01-11 11:46:21 -0500 | [diff] [blame] | 417 | public: |
Brian Salomon | 86c4001 | 2018-05-22 10:48:49 -0400 | [diff] [blame] | 418 | static void AssignPositionsAndTexCoords(V* vertices, const GrPerspQuad& quad, |
Brian Salomon | b5ef1f9 | 2018-01-11 11:46:21 -0500 | [diff] [blame] | 419 | const SkRect& texRect) { |
Brian Salomon | 86c4001 | 2018-05-22 10:48:49 -0400 | [diff] [blame] | 420 | SkPointPriv::SetRectTriStrip(&vertices[0].fTextureCoords, texRect, sizeof(V)); |
Brian Salomon | be3c1d2 | 2018-05-21 12:54:39 -0400 | [diff] [blame] | 421 | for (int i = 0; i < 4; ++i) { |
| 422 | vertices[i].fPosition = quad.point(i); |
| 423 | } |
| 424 | } |
| 425 | }; |
| 426 | |
Brian Salomon | 86c4001 | 2018-05-22 10:48:49 -0400 | [diff] [blame] | 427 | template<typename V> class VertexAAHandler<V, GrAA::kYes, SkPoint> { |
Brian Salomon | be3c1d2 | 2018-05-21 12:54:39 -0400 | [diff] [blame] | 428 | public: |
Brian Salomon | 86c4001 | 2018-05-22 10:48:49 -0400 | [diff] [blame] | 429 | static void AssignPositionsAndTexCoords(V* vertices, const GrPerspQuad& quad, |
Brian Salomon | be3c1d2 | 2018-05-21 12:54:39 -0400 | [diff] [blame] | 430 | const SkRect& texRect) { |
| 431 | SkASSERT((quad.w4f() == Sk4f(1.f)).allTrue()); |
Brian Salomon | 6872e94 | 2018-05-18 10:29:54 -0400 | [diff] [blame] | 432 | auto x = quad.x4f(); |
| 433 | auto y = quad.y4f(); |
| 434 | Sk4f a, b, c; |
| 435 | compute_quad_edges_and_outset_vertices(&x, &y, &a, &b, &c); |
Brian Salomon | b5ef1f9 | 2018-01-11 11:46:21 -0500 | [diff] [blame] | 436 | |
| 437 | for (int i = 0; i < 4; ++i) { |
Brian Salomon | 6872e94 | 2018-05-18 10:29:54 -0400 | [diff] [blame] | 438 | vertices[i].fPosition = {x[i], y[i]}; |
Brian Salomon | b5ef1f9 | 2018-01-11 11:46:21 -0500 | [diff] [blame] | 439 | for (int j = 0; j < 4; ++j) { |
Brian Salomon | 6872e94 | 2018-05-18 10:29:54 -0400 | [diff] [blame] | 440 | vertices[i].fEdges[j] = {a[j], b[j], c[j]}; |
Brian Salomon | b5ef1f9 | 2018-01-11 11:46:21 -0500 | [diff] [blame] | 441 | } |
| 442 | } |
| 443 | |
Brian Salomon | b5ef1f9 | 2018-01-11 11:46:21 -0500 | [diff] [blame] | 444 | AssignTexCoords(vertices, quad, texRect); |
| 445 | } |
| 446 | |
| 447 | private: |
Brian Salomon | 86c4001 | 2018-05-22 10:48:49 -0400 | [diff] [blame] | 448 | static void AssignTexCoords(V* vertices, const GrPerspQuad& quad, const SkRect& tex) { |
Brian Salomon | a33b67c | 2018-05-17 10:42:14 -0400 | [diff] [blame] | 449 | SkMatrix q = SkMatrix::MakeAll(quad.x(0), quad.x(1), quad.x(2), |
| 450 | quad.y(0), quad.y(1), quad.y(2), |
| 451 | 1.f, 1.f, 1.f); |
Brian Salomon | b5ef1f9 | 2018-01-11 11:46:21 -0500 | [diff] [blame] | 452 | SkMatrix qinv; |
| 453 | if (!q.invert(&qinv)) { |
| 454 | return; |
| 455 | } |
| 456 | SkMatrix t = SkMatrix::MakeAll(tex.fLeft, tex.fLeft, tex.fRight, |
| 457 | tex.fTop, tex.fBottom, tex.fTop, |
| 458 | 1.f, 1.f, 1.f); |
| 459 | SkMatrix map; |
| 460 | map.setConcat(t, qinv); |
Brian Salomon | 86c4001 | 2018-05-22 10:48:49 -0400 | [diff] [blame] | 461 | SkMatrixPriv::MapPointsWithStride(map, &vertices[0].fTextureCoords, sizeof(V), |
| 462 | &vertices[0].fPosition, sizeof(V), 4); |
Brian Salomon | b5ef1f9 | 2018-01-11 11:46:21 -0500 | [diff] [blame] | 463 | } |
| 464 | }; |
| 465 | |
Brian Salomon | 86c4001 | 2018-05-22 10:48:49 -0400 | [diff] [blame] | 466 | template<typename V> class VertexAAHandler<V, GrAA::kYes, SkPoint3> { |
Brian Salomon | be3c1d2 | 2018-05-21 12:54:39 -0400 | [diff] [blame] | 467 | public: |
Brian Salomon | 86c4001 | 2018-05-22 10:48:49 -0400 | [diff] [blame] | 468 | static void AssignPositionsAndTexCoords(V* vertices, const GrPerspQuad& quad, |
Brian Salomon | be3c1d2 | 2018-05-21 12:54:39 -0400 | [diff] [blame] | 469 | const SkRect& texRect) { |
| 470 | auto x = quad.x4f(); |
| 471 | auto y = quad.y4f(); |
| 472 | auto iw = quad.iw4f(); |
| 473 | x *= iw; |
| 474 | y *= iw; |
| 475 | |
| 476 | // Get an equation for w from device space coords. |
| 477 | SkMatrix P; |
| 478 | P.setAll(x[0], y[0], 1, x[1], y[1], 1, x[2], y[2], 1); |
| 479 | SkAssertResult(P.invert(&P)); |
| 480 | SkPoint3 weq{quad.w(0), quad.w(1), quad.w(2)}; |
| 481 | P.mapHomogeneousPoints(&weq, &weq, 1); |
| 482 | |
| 483 | Sk4f a, b, c; |
| 484 | compute_quad_edges_and_outset_vertices(&x, &y, &a, &b, &c); |
| 485 | |
| 486 | // Compute new w values for the output vertices; |
| 487 | auto w = Sk4f(weq.fX) * x + Sk4f(weq.fY) * y + Sk4f(weq.fZ); |
| 488 | x *= w; |
| 489 | y *= w; |
| 490 | |
| 491 | for (int i = 0; i < 4; ++i) { |
| 492 | vertices[i].fPosition = {x[i], y[i], w[i]}; |
| 493 | for (int j = 0; j < 4; ++j) { |
| 494 | vertices[i].fEdges[j] = {a[j], b[j], c[j]}; |
| 495 | } |
| 496 | } |
| 497 | |
| 498 | AssignTexCoords(vertices, quad, texRect); |
| 499 | } |
| 500 | |
| 501 | private: |
Brian Salomon | 86c4001 | 2018-05-22 10:48:49 -0400 | [diff] [blame] | 502 | static void AssignTexCoords(V* vertices, const GrPerspQuad& quad, const SkRect& tex) { |
Brian Salomon | be3c1d2 | 2018-05-21 12:54:39 -0400 | [diff] [blame] | 503 | SkMatrix q = SkMatrix::MakeAll(quad.x(0), quad.x(1), quad.x(2), |
| 504 | quad.y(0), quad.y(1), quad.y(2), |
| 505 | quad.w(0), quad.w(1), quad.w(2)); |
| 506 | SkMatrix qinv; |
| 507 | if (!q.invert(&qinv)) { |
| 508 | return; |
| 509 | } |
| 510 | SkMatrix t = SkMatrix::MakeAll(tex.fLeft, tex.fLeft, tex.fRight, |
| 511 | tex.fTop, tex.fBottom, tex.fTop, |
| 512 | 1.f, 1.f, 1.f); |
| 513 | SkMatrix map; |
| 514 | map.setConcat(t, qinv); |
| 515 | SkPoint3 tempTexCoords[4]; |
| 516 | SkMatrixPriv::MapHomogeneousPointsWithStride(map, tempTexCoords, sizeof(SkPoint3), |
Brian Salomon | 86c4001 | 2018-05-22 10:48:49 -0400 | [diff] [blame] | 517 | &vertices[0].fPosition, sizeof(V), 4); |
Brian Salomon | be3c1d2 | 2018-05-21 12:54:39 -0400 | [diff] [blame] | 518 | for (int i = 0; i < 4; ++i) { |
| 519 | auto invW = 1.f / tempTexCoords[i].fZ; |
| 520 | vertices[i].fTextureCoords.fX = tempTexCoords[i].fX * invW; |
| 521 | vertices[i].fTextureCoords.fY = tempTexCoords[i].fY * invW; |
| 522 | } |
| 523 | } |
| 524 | }; |
| 525 | |
Brian Salomon | 17031a7 | 2018-05-22 14:14:07 -0400 | [diff] [blame] | 526 | template <typename V, MultiTexture MT = V::kMultiTexture> struct TexIdAssigner; |
Brian Salomon | b5ef1f9 | 2018-01-11 11:46:21 -0500 | [diff] [blame] | 527 | |
Brian Salomon | 17031a7 | 2018-05-22 14:14:07 -0400 | [diff] [blame] | 528 | template <typename V> struct TexIdAssigner<V, MultiTexture::kYes> { |
Brian Salomon | 86c4001 | 2018-05-22 10:48:49 -0400 | [diff] [blame] | 529 | static void Assign(V* vertices, int textureIdx) { |
Brian Salomon | be3c1d2 | 2018-05-21 12:54:39 -0400 | [diff] [blame] | 530 | for (int i = 0; i < 4; ++i) { |
| 531 | vertices[i].fTextureIdx = textureIdx; |
| 532 | } |
Brian Salomon | b5ef1f9 | 2018-01-11 11:46:21 -0500 | [diff] [blame] | 533 | } |
| 534 | }; |
| 535 | |
Brian Salomon | 17031a7 | 2018-05-22 14:14:07 -0400 | [diff] [blame] | 536 | template <typename V> struct TexIdAssigner<V, MultiTexture::kNo> { |
Brian Salomon | 86c4001 | 2018-05-22 10:48:49 -0400 | [diff] [blame] | 537 | static void Assign(V* vertices, int textureIdx) {} |
Brian Salomon | b5ef1f9 | 2018-01-11 11:46:21 -0500 | [diff] [blame] | 538 | }; |
Brian Salomon | b80ffee | 2018-05-23 16:39:39 -0400 | [diff] [blame] | 539 | |
| 540 | template <typename V, Domain D = V::kDomain> struct DomainAssigner; |
| 541 | |
| 542 | template <typename V> struct DomainAssigner<V, Domain::kYes> { |
| 543 | static void Assign(V* vertices, Domain domain, GrSamplerState::Filter filter, |
| 544 | const SkRect& srcRect, GrSurfaceOrigin origin, float iw, float ih) { |
| 545 | static constexpr SkRect kLargeRect = {-2, -2, 2, 2}; |
| 546 | SkRect domainRect; |
| 547 | if (domain == Domain::kYes) { |
| 548 | auto ltrb = Sk4f::Load(&srcRect); |
| 549 | if (filter == GrSamplerState::Filter::kBilerp) { |
| 550 | auto rblt = SkNx_shuffle<2, 3, 0, 1>(ltrb); |
| 551 | auto whwh = (rblt - ltrb).abs(); |
| 552 | auto c = (rblt + ltrb) * 0.5f; |
| 553 | static const Sk4f kOffsets = {0.5f, 0.5f, -0.5f, -0.5f}; |
| 554 | ltrb = (whwh < 1.f).thenElse(c, ltrb + kOffsets); |
| 555 | } |
| 556 | ltrb *= Sk4f(iw, ih, iw, ih); |
| 557 | if (origin == kBottomLeft_GrSurfaceOrigin) { |
| 558 | static const Sk4f kMul = {1.f, -1.f, 1.f, -1.f}; |
| 559 | static const Sk4f kAdd = {0.f, 1.f, 0.f, 1.f}; |
| 560 | ltrb = SkNx_shuffle<0, 3, 2, 1>(kMul * ltrb + kAdd); |
| 561 | } |
| 562 | ltrb.store(&domainRect); |
| 563 | } else { |
| 564 | domainRect = kLargeRect; |
| 565 | } |
| 566 | for (int i = 0; i < 4; ++i) { |
| 567 | vertices[i].fTextureDomain = domainRect; |
| 568 | } |
| 569 | } |
| 570 | }; |
| 571 | |
| 572 | template <typename V> struct DomainAssigner<V, Domain::kNo> { |
| 573 | static void Assign(V*, Domain domain, GrSamplerState::Filter, const SkRect&, GrSurfaceOrigin, |
| 574 | float iw, float ih) { |
| 575 | SkASSERT(domain == Domain::kNo); |
| 576 | } |
| 577 | }; |
| 578 | |
Brian Salomon | b5ef1f9 | 2018-01-11 11:46:21 -0500 | [diff] [blame] | 579 | } // anonymous namespace |
| 580 | |
Brian Salomon | 86c4001 | 2018-05-22 10:48:49 -0400 | [diff] [blame] | 581 | template <typename V> |
Brian Salomon | be3c1d2 | 2018-05-21 12:54:39 -0400 | [diff] [blame] | 582 | static void tessellate_quad(const GrPerspQuad& devQuad, const SkRect& srcRect, GrColor color, |
Brian Salomon | b80ffee | 2018-05-23 16:39:39 -0400 | [diff] [blame] | 583 | GrSurfaceOrigin origin, GrSamplerState::Filter filter, V* vertices, |
| 584 | SkScalar iw, SkScalar ih, int textureIdx, Domain domain) { |
Brian Salomon | b5ef1f9 | 2018-01-11 11:46:21 -0500 | [diff] [blame] | 585 | SkRect texRect = { |
| 586 | iw * srcRect.fLeft, |
| 587 | ih * srcRect.fTop, |
| 588 | iw * srcRect.fRight, |
| 589 | ih * srcRect.fBottom |
| 590 | }; |
| 591 | if (origin == kBottomLeft_GrSurfaceOrigin) { |
| 592 | texRect.fTop = 1.f - texRect.fTop; |
| 593 | texRect.fBottom = 1.f - texRect.fBottom; |
| 594 | } |
Brian Salomon | 86c4001 | 2018-05-22 10:48:49 -0400 | [diff] [blame] | 595 | VertexAAHandler<V>::AssignPositionsAndTexCoords(vertices, devQuad, texRect); |
Brian Salomon | b5ef1f9 | 2018-01-11 11:46:21 -0500 | [diff] [blame] | 596 | vertices[0].fColor = color; |
| 597 | vertices[1].fColor = color; |
| 598 | vertices[2].fColor = color; |
| 599 | vertices[3].fColor = color; |
Brian Salomon | 86c4001 | 2018-05-22 10:48:49 -0400 | [diff] [blame] | 600 | TexIdAssigner<V>::Assign(vertices, textureIdx); |
Brian Salomon | b80ffee | 2018-05-23 16:39:39 -0400 | [diff] [blame] | 601 | DomainAssigner<V>::Assign(vertices, domain, filter, srcRect, origin, iw, ih); |
Brian Salomon | b5ef1f9 | 2018-01-11 11:46:21 -0500 | [diff] [blame] | 602 | } |
Brian Salomon | 17031a7 | 2018-05-22 14:14:07 -0400 | [diff] [blame] | 603 | |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 604 | /** |
| 605 | * Op that implements GrTextureOp::Make. It draws textured quads. Each quad can modulate against a |
| 606 | * the texture by color. The blend with the destination is always src-over. The edges are non-AA. |
| 607 | */ |
| 608 | class TextureOp final : public GrMeshDrawOp { |
| 609 | public: |
| 610 | static std::unique_ptr<GrDrawOp> Make(sk_sp<GrTextureProxy> proxy, |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 611 | GrSamplerState::Filter filter, GrColor color, |
Brian Salomon | 485b8c6 | 2018-01-12 15:11:06 -0500 | [diff] [blame] | 612 | const SkRect& srcRect, const SkRect& dstRect, |
Brian Salomon | b80ffee | 2018-05-23 16:39:39 -0400 | [diff] [blame] | 613 | GrAAType aaType, SkCanvas::SrcRectConstraint constraint, |
| 614 | const SkMatrix& viewMatrix, sk_sp<GrColorSpaceXform> csxf, |
| 615 | bool allowSRBInputs) { |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 616 | return std::unique_ptr<GrDrawOp>(new TextureOp(std::move(proxy), filter, color, srcRect, |
Brian Salomon | b80ffee | 2018-05-23 16:39:39 -0400 | [diff] [blame] | 617 | dstRect, aaType, constraint, viewMatrix, |
| 618 | std::move(csxf), allowSRBInputs)); |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 619 | } |
| 620 | |
Brian Salomon | 336ce7b | 2017-09-08 08:23:58 -0400 | [diff] [blame] | 621 | ~TextureOp() override { |
| 622 | if (fFinalized) { |
| 623 | auto proxies = this->proxies(); |
| 624 | for (int i = 0; i < fProxyCnt; ++i) { |
| 625 | proxies[i]->completedRead(); |
| 626 | } |
| 627 | if (fProxyCnt > 1) { |
| 628 | delete[] reinterpret_cast<const char*>(proxies); |
| 629 | } |
| 630 | } else { |
| 631 | SkASSERT(1 == fProxyCnt); |
| 632 | fProxy0->unref(); |
| 633 | } |
| 634 | } |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 635 | |
| 636 | const char* name() const override { return "TextureOp"; } |
| 637 | |
Robert Phillips | f1748f5 | 2017-09-14 14:11:24 -0400 | [diff] [blame] | 638 | void visitProxies(const VisitProxyFunc& func) const override { |
Robert Phillips | b493eeb | 2017-09-13 13:10:52 -0400 | [diff] [blame] | 639 | auto proxies = this->proxies(); |
| 640 | for (int i = 0; i < fProxyCnt; ++i) { |
| 641 | func(proxies[i]); |
| 642 | } |
| 643 | } |
| 644 | |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 645 | SkString dumpInfo() const override { |
| 646 | SkString str; |
Brian Salomon | 336ce7b | 2017-09-08 08:23:58 -0400 | [diff] [blame] | 647 | str.appendf("AllowSRGBInputs: %d\n", fAllowSRGBInputs); |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 648 | str.appendf("# draws: %d\n", fDraws.count()); |
Brian Salomon | 336ce7b | 2017-09-08 08:23:58 -0400 | [diff] [blame] | 649 | auto proxies = this->proxies(); |
| 650 | for (int i = 0; i < fProxyCnt; ++i) { |
| 651 | str.appendf("Proxy ID %d: %d, Filter: %d\n", i, proxies[i]->uniqueID().asUInt(), |
| 652 | static_cast<int>(this->filters()[i])); |
| 653 | } |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 654 | for (int i = 0; i < fDraws.count(); ++i) { |
| 655 | const Draw& draw = fDraws[i]; |
| 656 | str.appendf( |
Brian Salomon | 336ce7b | 2017-09-08 08:23:58 -0400 | [diff] [blame] | 657 | "%d: Color: 0x%08x, ProxyIdx: %d, TexRect [L: %.2f, T: %.2f, R: %.2f, B: %.2f] " |
| 658 | "Quad [(%.2f, %.2f), (%.2f, %.2f), (%.2f, %.2f), (%.2f, %.2f)]\n", |
Brian Salomon | b80ffee | 2018-05-23 16:39:39 -0400 | [diff] [blame] | 659 | i, draw.color(), draw.textureIdx(), draw.srcRect().fLeft, draw.srcRect().fTop, |
| 660 | draw.srcRect().fRight, draw.srcRect().fBottom, draw.quad().point(0).fX, |
| 661 | draw.quad().point(0).fY, draw.quad().point(1).fX, draw.quad().point(1).fY, |
| 662 | draw.quad().point(2).fX, draw.quad().point(2).fY, draw.quad().point(3).fX, |
| 663 | draw.quad().point(3).fY); |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 664 | } |
| 665 | str += INHERITED::dumpInfo(); |
| 666 | return str; |
| 667 | } |
| 668 | |
Brian Osman | 9a725dd | 2017-09-20 09:53:22 -0400 | [diff] [blame] | 669 | RequiresDstTexture finalize(const GrCaps& caps, const GrAppliedClip* clip, |
| 670 | GrPixelConfigIsClamped dstIsClamped) override { |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 671 | SkASSERT(!fFinalized); |
Brian Salomon | 336ce7b | 2017-09-08 08:23:58 -0400 | [diff] [blame] | 672 | SkASSERT(1 == fProxyCnt); |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 673 | fFinalized = true; |
Brian Salomon | 336ce7b | 2017-09-08 08:23:58 -0400 | [diff] [blame] | 674 | fProxy0->addPendingRead(); |
| 675 | fProxy0->unref(); |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 676 | return RequiresDstTexture::kNo; |
| 677 | } |
| 678 | |
Brian Salomon | 485b8c6 | 2018-01-12 15:11:06 -0500 | [diff] [blame] | 679 | FixedFunctionFlags fixedFunctionFlags() const override { |
| 680 | return this->aaType() == GrAAType::kMSAA ? FixedFunctionFlags::kUsesHWAA |
| 681 | : FixedFunctionFlags::kNone; |
| 682 | } |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 683 | |
| 684 | DEFINE_OP_CLASS_ID |
| 685 | |
| 686 | private: |
Brian Salomon | 762d5e7 | 2017-12-01 10:25:08 -0500 | [diff] [blame] | 687 | |
| 688 | // This is used in a heursitic for choosing a code path. We don't care what happens with |
| 689 | // really large rects, infs, nans, etc. |
| 690 | #if defined(__clang__) && (__clang_major__ * 1000 + __clang_minor__) >= 3007 |
| 691 | __attribute__((no_sanitize("float-cast-overflow"))) |
| 692 | #endif |
Brian Salomon | b5ef1f9 | 2018-01-11 11:46:21 -0500 | [diff] [blame] | 693 | size_t RectSizeAsSizeT(const SkRect& rect) {; |
Brian Salomon | 762d5e7 | 2017-12-01 10:25:08 -0500 | [diff] [blame] | 694 | return static_cast<size_t>(SkTMax(rect.width(), 1.f) * SkTMax(rect.height(), 1.f)); |
| 695 | } |
| 696 | |
Brian Salomon | 336ce7b | 2017-09-08 08:23:58 -0400 | [diff] [blame] | 697 | static constexpr int kMaxTextures = TextureGeometryProcessor::kMaxTextures; |
| 698 | |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 699 | TextureOp(sk_sp<GrTextureProxy> proxy, GrSamplerState::Filter filter, GrColor color, |
Brian Salomon | 485b8c6 | 2018-01-12 15:11:06 -0500 | [diff] [blame] | 700 | const SkRect& srcRect, const SkRect& dstRect, GrAAType aaType, |
Brian Salomon | b80ffee | 2018-05-23 16:39:39 -0400 | [diff] [blame] | 701 | SkCanvas::SrcRectConstraint constraint, const SkMatrix& viewMatrix, |
| 702 | sk_sp<GrColorSpaceXform> csxf, bool allowSRGBInputs) |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 703 | : INHERITED(ClassID()) |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 704 | , fColorSpaceXform(std::move(csxf)) |
Brian Salomon | 336ce7b | 2017-09-08 08:23:58 -0400 | [diff] [blame] | 705 | , fProxy0(proxy.release()) |
| 706 | , fFilter0(filter) |
| 707 | , fProxyCnt(1) |
Brian Salomon | 485b8c6 | 2018-01-12 15:11:06 -0500 | [diff] [blame] | 708 | , fAAType(static_cast<unsigned>(aaType)) |
Brian Salomon | b5ef1f9 | 2018-01-11 11:46:21 -0500 | [diff] [blame] | 709 | , fFinalized(0) |
| 710 | , fAllowSRGBInputs(allowSRGBInputs ? 1 : 0) { |
Brian Salomon | 485b8c6 | 2018-01-12 15:11:06 -0500 | [diff] [blame] | 711 | SkASSERT(aaType != GrAAType::kMixedSamples); |
Brian Salomon | be3c1d2 | 2018-05-21 12:54:39 -0400 | [diff] [blame] | 712 | fPerspective = viewMatrix.hasPerspective(); |
Brian Salomon | 594b64c | 2018-05-29 12:47:57 -0400 | [diff] [blame] | 713 | auto quad = GrPerspQuad(dstRect, viewMatrix); |
| 714 | auto bounds = quad.bounds(); |
| 715 | #ifndef SK_DONT_DROP_UNNECESSARY_AA_IN_TEXTURE_OP |
| 716 | if (GrAAType::kCoverage == this->aaType() && viewMatrix.rectStaysRect()) { |
| 717 | // Disable coverage AA when rect falls on integers in device space. |
| 718 | auto is_int = [](float f) { return f == sk_float_floor(f); }; |
| 719 | if (is_int(bounds.fLeft) && is_int(bounds.fTop) && is_int(bounds.fRight) && |
| 720 | is_int(bounds.fBottom)) { |
| 721 | fAAType = static_cast<unsigned>(GrAAType::kNone); |
| 722 | // We may have had a strict constraint with nearest filter soley due to possible AA |
| 723 | // bloat. In that case it's no longer necessary. |
| 724 | if (constraint == SkCanvas::kStrict_SrcRectConstraint && |
| 725 | filter == GrSamplerState::Filter::kNearest) { |
| 726 | constraint = SkCanvas::kFast_SrcRectConstraint; |
| 727 | } |
| 728 | } |
| 729 | } |
| 730 | #endif |
| 731 | const auto& draw = fDraws.emplace_back(srcRect, 0, quad, constraint, color); |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 732 | this->setBounds(bounds, HasAABloat::kNo, IsZeroArea::kNo); |
Brian Salomon | 594b64c | 2018-05-29 12:47:57 -0400 | [diff] [blame] | 733 | fDomain = static_cast<bool>(draw.domain()); |
Brian Salomon | 762d5e7 | 2017-12-01 10:25:08 -0500 | [diff] [blame] | 734 | fMaxApproxDstPixelArea = RectSizeAsSizeT(bounds); |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 735 | } |
| 736 | |
Brian Salomon | b80ffee | 2018-05-23 16:39:39 -0400 | [diff] [blame] | 737 | template <typename Pos, MultiTexture MT, Domain D, GrAA AA> |
Brian Salomon | 17031a7 | 2018-05-22 14:14:07 -0400 | [diff] [blame] | 738 | void tess(void* v, const float iw[], const float ih[], const GrGeometryProcessor* gp) { |
Brian Salomon | b80ffee | 2018-05-23 16:39:39 -0400 | [diff] [blame] | 739 | using Vertex = TextureGeometryProcessor::Vertex<Pos, MT, D, AA>; |
Brian Salomon | 17031a7 | 2018-05-22 14:14:07 -0400 | [diff] [blame] | 740 | SkASSERT(gp->getVertexStride() == sizeof(Vertex)); |
| 741 | auto vertices = static_cast<Vertex*>(v); |
| 742 | auto proxies = this->proxies(); |
Brian Salomon | b80ffee | 2018-05-23 16:39:39 -0400 | [diff] [blame] | 743 | auto filters = this->filters(); |
Brian Salomon | 17031a7 | 2018-05-22 14:14:07 -0400 | [diff] [blame] | 744 | for (const auto& draw : fDraws) { |
Brian Salomon | b80ffee | 2018-05-23 16:39:39 -0400 | [diff] [blame] | 745 | auto textureIdx = draw.textureIdx(); |
| 746 | auto origin = proxies[textureIdx]->origin(); |
| 747 | tessellate_quad<Vertex>(draw.quad(), draw.srcRect(), draw.color(), origin, |
| 748 | filters[textureIdx], vertices, iw[textureIdx], ih[textureIdx], |
| 749 | textureIdx, draw.domain()); |
Brian Salomon | 17031a7 | 2018-05-22 14:14:07 -0400 | [diff] [blame] | 750 | vertices += 4; |
| 751 | } |
| 752 | } |
| 753 | |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 754 | void onPrepareDraws(Target* target) override { |
Brian Salomon | 336ce7b | 2017-09-08 08:23:58 -0400 | [diff] [blame] | 755 | sk_sp<GrTextureProxy> proxiesSPs[kMaxTextures]; |
| 756 | auto proxies = this->proxies(); |
| 757 | auto filters = this->filters(); |
| 758 | for (int i = 0; i < fProxyCnt; ++i) { |
| 759 | if (!proxies[i]->instantiate(target->resourceProvider())) { |
| 760 | return; |
| 761 | } |
| 762 | proxiesSPs[i] = sk_ref_sp(proxies[i]); |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 763 | } |
Brian Salomon | 336ce7b | 2017-09-08 08:23:58 -0400 | [diff] [blame] | 764 | |
Brian Salomon | b80ffee | 2018-05-23 16:39:39 -0400 | [diff] [blame] | 765 | Domain domain = fDomain ? Domain::kYes : Domain::kNo; |
Brian Salomon | 485b8c6 | 2018-01-12 15:11:06 -0500 | [diff] [blame] | 766 | bool coverageAA = GrAAType::kCoverage == this->aaType(); |
Brian Salomon | be3c1d2 | 2018-05-21 12:54:39 -0400 | [diff] [blame] | 767 | sk_sp<GrGeometryProcessor> gp = TextureGeometryProcessor::Make( |
| 768 | proxiesSPs, fProxyCnt, std::move(fColorSpaceXform), coverageAA, fPerspective, |
Brian Salomon | b80ffee | 2018-05-23 16:39:39 -0400 | [diff] [blame] | 769 | domain, filters, *target->caps().shaderCaps()); |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 770 | GrPipeline::InitArgs args; |
| 771 | args.fProxy = target->proxy(); |
| 772 | args.fCaps = &target->caps(); |
| 773 | args.fResourceProvider = target->resourceProvider(); |
Brian Salomon | 485b8c6 | 2018-01-12 15:11:06 -0500 | [diff] [blame] | 774 | args.fFlags = 0; |
| 775 | if (fAllowSRGBInputs) { |
| 776 | args.fFlags |= GrPipeline::kAllowSRGBInputs_Flag; |
| 777 | } |
| 778 | if (GrAAType::kMSAA == this->aaType()) { |
| 779 | args.fFlags |= GrPipeline::kHWAntialias_Flag; |
| 780 | } |
| 781 | |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 782 | const GrPipeline* pipeline = target->allocPipeline(args, GrProcessorSet::MakeEmptySet(), |
| 783 | target->detachAppliedClip()); |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 784 | int vstart; |
| 785 | const GrBuffer* vbuffer; |
Brian Salomon | 336ce7b | 2017-09-08 08:23:58 -0400 | [diff] [blame] | 786 | void* vdata = target->makeVertexSpace(gp->getVertexStride(), 4 * fDraws.count(), &vbuffer, |
| 787 | &vstart); |
| 788 | if (!vdata) { |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 789 | SkDebugf("Could not allocate vertices\n"); |
| 790 | return; |
| 791 | } |
Brian Salomon | be3c1d2 | 2018-05-21 12:54:39 -0400 | [diff] [blame] | 792 | |
Brian Salomon | be3c1d2 | 2018-05-21 12:54:39 -0400 | [diff] [blame] | 793 | float iw[kMaxTextures]; |
| 794 | float ih[kMaxTextures]; |
| 795 | for (int t = 0; t < fProxyCnt; ++t) { |
| 796 | const auto* texture = proxies[t]->priv().peekTexture(); |
| 797 | iw[t] = 1.f / texture->width(); |
| 798 | ih[t] = 1.f / texture->height(); |
| 799 | } |
| 800 | |
Brian Salomon | 16b1eab | 2018-05-24 16:08:28 -0400 | [diff] [blame] | 801 | #if defined(_MSC_VER) && _MSC_VER <= 1910 |
| 802 | # define MAYBE_CONSTEXPR const |
| 803 | #else |
| 804 | # define MAYBE_CONSTEXPR constexpr |
| 805 | #endif |
Brian Salomon | b80ffee | 2018-05-23 16:39:39 -0400 | [diff] [blame] | 806 | using TessFn = |
| 807 | decltype(&TextureOp::tess<SkPoint, MultiTexture::kNo, Domain::kNo, GrAA::kNo>); |
Brian Salomon | 16b1eab | 2018-05-24 16:08:28 -0400 | [diff] [blame] | 808 | static MAYBE_CONSTEXPR TessFn kTessFns[] = { |
Brian Salomon | b80ffee | 2018-05-23 16:39:39 -0400 | [diff] [blame] | 809 | &TextureOp::tess<SkPoint, MultiTexture::kNo, Domain::kNo, GrAA::kNo>, |
| 810 | &TextureOp::tess<SkPoint, MultiTexture::kNo, Domain::kNo, GrAA::kYes>, |
| 811 | &TextureOp::tess<SkPoint, MultiTexture::kNo, Domain::kYes, GrAA::kNo>, |
| 812 | &TextureOp::tess<SkPoint, MultiTexture::kNo, Domain::kYes, GrAA::kYes>, |
| 813 | &TextureOp::tess<SkPoint, MultiTexture::kYes, Domain::kNo, GrAA::kNo>, |
| 814 | &TextureOp::tess<SkPoint, MultiTexture::kYes, Domain::kNo, GrAA::kYes>, |
| 815 | &TextureOp::tess<SkPoint, MultiTexture::kYes, Domain::kYes, GrAA::kNo>, |
| 816 | &TextureOp::tess<SkPoint, MultiTexture::kYes, Domain::kYes, GrAA::kYes>, |
| 817 | &TextureOp::tess<SkPoint3, MultiTexture::kNo, Domain::kNo, GrAA::kNo>, |
| 818 | &TextureOp::tess<SkPoint3, MultiTexture::kNo, Domain::kNo, GrAA::kYes>, |
| 819 | &TextureOp::tess<SkPoint3, MultiTexture::kNo, Domain::kYes, GrAA::kNo>, |
| 820 | &TextureOp::tess<SkPoint3, MultiTexture::kNo, Domain::kYes, GrAA::kYes>, |
| 821 | &TextureOp::tess<SkPoint3, MultiTexture::kYes, Domain::kNo, GrAA::kNo>, |
| 822 | &TextureOp::tess<SkPoint3, MultiTexture::kYes, Domain::kNo, GrAA::kYes>, |
| 823 | &TextureOp::tess<SkPoint3, MultiTexture::kYes, Domain::kYes, GrAA::kNo>, |
| 824 | &TextureOp::tess<SkPoint3, MultiTexture::kYes, Domain::kYes, GrAA::kYes>, |
| 825 | }; |
Brian Salomon | 16b1eab | 2018-05-24 16:08:28 -0400 | [diff] [blame] | 826 | #undef MAYBE_CONSTEXPR |
Brian Salomon | b80ffee | 2018-05-23 16:39:39 -0400 | [diff] [blame] | 827 | int tessFnIdx = 0; |
| 828 | tessFnIdx |= coverageAA ? 0x1 : 0x0; |
| 829 | tessFnIdx |= fDomain ? 0x2 : 0x0; |
| 830 | tessFnIdx |= (fProxyCnt > 1) ? 0x4 : 0x0; |
| 831 | tessFnIdx |= fPerspective ? 0x8 : 0x0; |
| 832 | (this->*(kTessFns[tessFnIdx]))(vdata, iw, ih, gp.get()); |
| 833 | |
Brian Salomon | 57caa66 | 2017-10-18 12:21:05 +0000 | [diff] [blame] | 834 | GrPrimitiveType primitiveType = |
| 835 | fDraws.count() > 1 ? GrPrimitiveType::kTriangles : GrPrimitiveType::kTriangleStrip; |
| 836 | GrMesh mesh(primitiveType); |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 837 | if (fDraws.count() > 1) { |
Brian Salomon | 57caa66 | 2017-10-18 12:21:05 +0000 | [diff] [blame] | 838 | sk_sp<const GrBuffer> ibuffer = target->resourceProvider()->refQuadIndexBuffer(); |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 839 | if (!ibuffer) { |
| 840 | SkDebugf("Could not allocate quad indices\n"); |
| 841 | return; |
| 842 | } |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 843 | mesh.setIndexedPatterned(ibuffer.get(), 6, 4, fDraws.count(), |
| 844 | GrResourceProvider::QuadCountOfQuadBuffer()); |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 845 | } else { |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 846 | mesh.setNonIndexedNonInstanced(4); |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 847 | } |
Brian Salomon | 57caa66 | 2017-10-18 12:21:05 +0000 | [diff] [blame] | 848 | mesh.setVertexData(vbuffer, vstart); |
| 849 | target->draw(gp.get(), pipeline, mesh); |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 850 | } |
| 851 | |
| 852 | bool onCombineIfPossible(GrOp* t, const GrCaps& caps) override { |
| 853 | const auto* that = t->cast<TextureOp>(); |
Brian Salomon | 762d5e7 | 2017-12-01 10:25:08 -0500 | [diff] [blame] | 854 | const auto& shaderCaps = *caps.shaderCaps(); |
Brian Salomon | 336ce7b | 2017-09-08 08:23:58 -0400 | [diff] [blame] | 855 | if (!GrColorSpaceXform::Equals(fColorSpaceXform.get(), that->fColorSpaceXform.get())) { |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 856 | return false; |
| 857 | } |
Brian Salomon | 485b8c6 | 2018-01-12 15:11:06 -0500 | [diff] [blame] | 858 | if (this->aaType() != that->aaType()) { |
Brian Salomon | b5ef1f9 | 2018-01-11 11:46:21 -0500 | [diff] [blame] | 859 | return false; |
| 860 | } |
Brian Salomon | 336ce7b | 2017-09-08 08:23:58 -0400 | [diff] [blame] | 861 | // Because of an issue where GrColorSpaceXform adds the same function every time it is used |
| 862 | // in a texture lookup, we only allow multiple textures when there is no transform. |
Brian Salomon | 762d5e7 | 2017-12-01 10:25:08 -0500 | [diff] [blame] | 863 | if (TextureGeometryProcessor::SupportsMultitexture(shaderCaps) && !fColorSpaceXform && |
| 864 | fMaxApproxDstPixelArea <= shaderCaps.disableImageMultitexturingDstRectAreaThreshold() && |
| 865 | that->fMaxApproxDstPixelArea <= |
| 866 | shaderCaps.disableImageMultitexturingDstRectAreaThreshold()) { |
Brian Salomon | 336ce7b | 2017-09-08 08:23:58 -0400 | [diff] [blame] | 867 | int map[kMaxTextures]; |
Brian Salomon | 762d5e7 | 2017-12-01 10:25:08 -0500 | [diff] [blame] | 868 | int numNewProxies = this->mergeProxies(that, map, shaderCaps); |
Brian Salomon | 336ce7b | 2017-09-08 08:23:58 -0400 | [diff] [blame] | 869 | if (numNewProxies < 0) { |
| 870 | return false; |
| 871 | } |
| 872 | if (1 == fProxyCnt && numNewProxies) { |
| 873 | void* mem = new char[(sizeof(GrSamplerState::Filter) + sizeof(GrTextureProxy*)) * |
| 874 | kMaxTextures]; |
| 875 | auto proxies = reinterpret_cast<GrTextureProxy**>(mem); |
| 876 | auto filters = reinterpret_cast<GrSamplerState::Filter*>(proxies + kMaxTextures); |
| 877 | proxies[0] = fProxy0; |
| 878 | filters[0] = fFilter0; |
| 879 | fProxyArray = proxies; |
| 880 | } |
| 881 | fProxyCnt += numNewProxies; |
| 882 | auto thisProxies = fProxyArray; |
| 883 | auto thatProxies = that->proxies(); |
| 884 | auto thatFilters = that->filters(); |
| 885 | auto thisFilters = reinterpret_cast<GrSamplerState::Filter*>(thisProxies + |
| 886 | kMaxTextures); |
| 887 | for (int i = 0; i < that->fProxyCnt; ++i) { |
| 888 | if (map[i] < 0) { |
| 889 | thatProxies[i]->addPendingRead(); |
Robert Phillips | b493eeb | 2017-09-13 13:10:52 -0400 | [diff] [blame] | 890 | |
Brian Salomon | 336ce7b | 2017-09-08 08:23:58 -0400 | [diff] [blame] | 891 | thisProxies[-map[i]] = thatProxies[i]; |
| 892 | thisFilters[-map[i]] = thatFilters[i]; |
| 893 | map[i] = -map[i]; |
| 894 | } |
| 895 | } |
| 896 | int firstNewDraw = fDraws.count(); |
| 897 | fDraws.push_back_n(that->fDraws.count(), that->fDraws.begin()); |
| 898 | for (int i = firstNewDraw; i < fDraws.count(); ++i) { |
Brian Salomon | b80ffee | 2018-05-23 16:39:39 -0400 | [diff] [blame] | 899 | fDraws[i].setTextureIdx(map[fDraws[i].textureIdx()]); |
Brian Salomon | 336ce7b | 2017-09-08 08:23:58 -0400 | [diff] [blame] | 900 | } |
| 901 | } else { |
Brian Salomon | bbf0575 | 2017-11-30 11:30:48 -0500 | [diff] [blame] | 902 | // We can get here when one of the ops is already multitextured but the other cannot |
| 903 | // be because of the dst rect size. |
| 904 | if (fProxyCnt > 1 || that->fProxyCnt > 1) { |
| 905 | return false; |
| 906 | } |
Brian Salomon | 336ce7b | 2017-09-08 08:23:58 -0400 | [diff] [blame] | 907 | if (fProxy0->uniqueID() != that->fProxy0->uniqueID() || fFilter0 != that->fFilter0) { |
| 908 | return false; |
| 909 | } |
| 910 | fDraws.push_back_n(that->fDraws.count(), that->fDraws.begin()); |
| 911 | } |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 912 | this->joinBounds(*that); |
Brian Salomon | 762d5e7 | 2017-12-01 10:25:08 -0500 | [diff] [blame] | 913 | fMaxApproxDstPixelArea = SkTMax(that->fMaxApproxDstPixelArea, fMaxApproxDstPixelArea); |
Brian Salomon | be3c1d2 | 2018-05-21 12:54:39 -0400 | [diff] [blame] | 914 | fPerspective |= that->fPerspective; |
Brian Salomon | b80ffee | 2018-05-23 16:39:39 -0400 | [diff] [blame] | 915 | fDomain |= that->fDomain; |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 916 | return true; |
| 917 | } |
| 918 | |
Brian Salomon | 336ce7b | 2017-09-08 08:23:58 -0400 | [diff] [blame] | 919 | /** |
| 920 | * Determines a mapping of indices from that's proxy array to this's proxy array. A negative map |
| 921 | * value means that's proxy should be added to this's proxy array at the absolute value of |
| 922 | * the map entry. If it is determined that the ops shouldn't combine their proxies then a |
| 923 | * negative value is returned. Otherwise, return value indicates the number of proxies that have |
| 924 | * to be added to this op or, equivalently, the number of negative entries in map. |
| 925 | */ |
| 926 | int mergeProxies(const TextureOp* that, int map[kMaxTextures], const GrShaderCaps& caps) const { |
| 927 | std::fill_n(map, kMaxTextures, -kMaxTextures); |
| 928 | int sharedProxyCnt = 0; |
| 929 | auto thisProxies = this->proxies(); |
| 930 | auto thisFilters = this->filters(); |
| 931 | auto thatProxies = that->proxies(); |
| 932 | auto thatFilters = that->filters(); |
| 933 | for (int i = 0; i < fProxyCnt; ++i) { |
| 934 | for (int j = 0; j < that->fProxyCnt; ++j) { |
| 935 | if (thisProxies[i]->uniqueID() == thatProxies[j]->uniqueID()) { |
| 936 | if (thisFilters[i] != thatFilters[j]) { |
| 937 | // In GL we don't currently support using the same texture with different |
| 938 | // samplers. If we added support for sampler objects and a cap bit to know |
| 939 | // it's ok to use different filter modes then we could support this. |
| 940 | // Otherwise, we could also only allow a single filter mode for each op |
| 941 | // instance. |
| 942 | return -1; |
| 943 | } |
| 944 | map[j] = i; |
| 945 | ++sharedProxyCnt; |
| 946 | break; |
| 947 | } |
| 948 | } |
| 949 | } |
Brian Salomon | 2b6f614 | 2017-11-13 11:49:13 -0500 | [diff] [blame] | 950 | int actualMaxTextures = SkTMin(caps.maxFragmentSamplers(), kMaxTextures); |
Brian Salomon | 336ce7b | 2017-09-08 08:23:58 -0400 | [diff] [blame] | 951 | int newProxyCnt = that->fProxyCnt - sharedProxyCnt; |
| 952 | if (newProxyCnt + fProxyCnt > actualMaxTextures) { |
| 953 | return -1; |
| 954 | } |
| 955 | GrPixelConfig config = thisProxies[0]->config(); |
| 956 | int nextSlot = fProxyCnt; |
| 957 | for (int j = 0; j < that->fProxyCnt; ++j) { |
| 958 | // We want to avoid making many shaders because of different permutations of shader |
| 959 | // based swizzle and sampler types. The approach taken here is to require the configs to |
| 960 | // be the same and to only allow already instantiated proxies that have the most |
| 961 | // common sampler type. Otherwise we don't merge. |
| 962 | if (thatProxies[j]->config() != config) { |
| 963 | return -1; |
| 964 | } |
| 965 | if (GrTexture* tex = thatProxies[j]->priv().peekTexture()) { |
| 966 | if (tex->texturePriv().samplerType() != kTexture2DSampler_GrSLType) { |
| 967 | return -1; |
| 968 | } |
| 969 | } |
| 970 | if (map[j] < 0) { |
| 971 | map[j] = -(nextSlot++); |
| 972 | } |
| 973 | } |
| 974 | return newProxyCnt; |
| 975 | } |
| 976 | |
Brian Salomon | 485b8c6 | 2018-01-12 15:11:06 -0500 | [diff] [blame] | 977 | GrAAType aaType() const { return static_cast<GrAAType>(fAAType); } |
Brian Salomon | b5ef1f9 | 2018-01-11 11:46:21 -0500 | [diff] [blame] | 978 | |
Brian Salomon | 336ce7b | 2017-09-08 08:23:58 -0400 | [diff] [blame] | 979 | GrTextureProxy* const* proxies() const { return fProxyCnt > 1 ? fProxyArray : &fProxy0; } |
| 980 | |
| 981 | const GrSamplerState::Filter* filters() const { |
| 982 | if (fProxyCnt > 1) { |
| 983 | return reinterpret_cast<const GrSamplerState::Filter*>(fProxyArray + kMaxTextures); |
| 984 | } |
| 985 | return &fFilter0; |
| 986 | } |
| 987 | |
Brian Salomon | b80ffee | 2018-05-23 16:39:39 -0400 | [diff] [blame] | 988 | class Draw { |
| 989 | public: |
| 990 | Draw(const SkRect& srcRect, int textureIdx, const GrPerspQuad& quad, |
| 991 | SkCanvas::SrcRectConstraint constraint, GrColor color) |
| 992 | : fSrcRect(srcRect) |
| 993 | , fHasDomain(constraint == SkCanvas::kStrict_SrcRectConstraint) |
| 994 | , fTextureIdx(SkToUInt(textureIdx)) |
| 995 | , fQuad(quad) |
| 996 | , fColor(color) {} |
| 997 | const GrPerspQuad& quad() const { return fQuad; } |
| 998 | int textureIdx() const { return SkToInt(fTextureIdx); } |
| 999 | const SkRect& srcRect() const { return fSrcRect; } |
| 1000 | GrColor color() const { return fColor; } |
| 1001 | Domain domain() const { return Domain(fHasDomain); } |
| 1002 | void setTextureIdx(int i) { fTextureIdx = SkToUInt(i); } |
| 1003 | |
| 1004 | private: |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 1005 | SkRect fSrcRect; |
Brian Salomon | b80ffee | 2018-05-23 16:39:39 -0400 | [diff] [blame] | 1006 | unsigned fHasDomain : 1; |
| 1007 | unsigned fTextureIdx : 31; |
Brian Salomon | be3c1d2 | 2018-05-21 12:54:39 -0400 | [diff] [blame] | 1008 | GrPerspQuad fQuad; |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 1009 | GrColor fColor; |
| 1010 | }; |
| 1011 | SkSTArray<1, Draw, true> fDraws; |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 1012 | sk_sp<GrColorSpaceXform> fColorSpaceXform; |
Brian Salomon | 336ce7b | 2017-09-08 08:23:58 -0400 | [diff] [blame] | 1013 | // Initially we store a single proxy ptr and a single filter. If we grow to have more than |
| 1014 | // one proxy we instead store pointers to dynamically allocated arrays of size kMaxTextures |
| 1015 | // followed by kMaxTextures filters. |
| 1016 | union { |
| 1017 | GrTextureProxy* fProxy0; |
| 1018 | GrTextureProxy** fProxyArray; |
| 1019 | }; |
Brian Salomon | bbf0575 | 2017-11-30 11:30:48 -0500 | [diff] [blame] | 1020 | size_t fMaxApproxDstPixelArea; |
Brian Salomon | 336ce7b | 2017-09-08 08:23:58 -0400 | [diff] [blame] | 1021 | GrSamplerState::Filter fFilter0; |
| 1022 | uint8_t fProxyCnt; |
Brian Salomon | 485b8c6 | 2018-01-12 15:11:06 -0500 | [diff] [blame] | 1023 | unsigned fAAType : 2; |
Brian Salomon | be3c1d2 | 2018-05-21 12:54:39 -0400 | [diff] [blame] | 1024 | unsigned fPerspective : 1; |
Brian Salomon | b80ffee | 2018-05-23 16:39:39 -0400 | [diff] [blame] | 1025 | unsigned fDomain : 1; |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 1026 | // Used to track whether fProxy is ref'ed or has a pending IO after finalize() is called. |
Brian Salomon | b5ef1f9 | 2018-01-11 11:46:21 -0500 | [diff] [blame] | 1027 | unsigned fFinalized : 1; |
| 1028 | unsigned fAllowSRGBInputs : 1; |
Brian Salomon | 336ce7b | 2017-09-08 08:23:58 -0400 | [diff] [blame] | 1029 | |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 1030 | typedef GrMeshDrawOp INHERITED; |
| 1031 | }; |
| 1032 | |
Brian Salomon | 336ce7b | 2017-09-08 08:23:58 -0400 | [diff] [blame] | 1033 | constexpr int TextureGeometryProcessor::kMaxTextures; |
| 1034 | constexpr int TextureOp::kMaxTextures; |
| 1035 | |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 1036 | } // anonymous namespace |
| 1037 | |
| 1038 | namespace GrTextureOp { |
| 1039 | |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 1040 | std::unique_ptr<GrDrawOp> Make(sk_sp<GrTextureProxy> proxy, GrSamplerState::Filter filter, |
Brian Salomon | 485b8c6 | 2018-01-12 15:11:06 -0500 | [diff] [blame] | 1041 | GrColor color, const SkRect& srcRect, const SkRect& dstRect, |
Brian Salomon | b80ffee | 2018-05-23 16:39:39 -0400 | [diff] [blame] | 1042 | GrAAType aaType, SkCanvas::SrcRectConstraint constraint, |
| 1043 | const SkMatrix& viewMatrix, sk_sp<GrColorSpaceXform> csxf, |
| 1044 | bool allowSRGBInputs) { |
| 1045 | return TextureOp::Make(std::move(proxy), filter, color, srcRect, dstRect, aaType, constraint, |
| 1046 | viewMatrix, std::move(csxf), allowSRGBInputs); |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 1047 | } |
| 1048 | |
| 1049 | } // namespace GrTextureOp |
| 1050 | |
| 1051 | #if GR_TEST_UTILS |
| 1052 | #include "GrContext.h" |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 1053 | #include "GrContextPriv.h" |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 1054 | #include "GrProxyProvider.h" |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 1055 | |
| 1056 | GR_DRAW_OP_TEST_DEFINE(TextureOp) { |
| 1057 | GrSurfaceDesc desc; |
| 1058 | desc.fConfig = kRGBA_8888_GrPixelConfig; |
| 1059 | desc.fHeight = random->nextULessThan(90) + 10; |
| 1060 | desc.fWidth = random->nextULessThan(90) + 10; |
Brian Salomon | 2a4f983 | 2018-03-03 22:43:43 -0500 | [diff] [blame] | 1061 | auto origin = random->nextBool() ? kTopLeft_GrSurfaceOrigin : kBottomLeft_GrSurfaceOrigin; |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 1062 | SkBackingFit fit = random->nextBool() ? SkBackingFit::kApprox : SkBackingFit::kExact; |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 1063 | |
| 1064 | GrProxyProvider* proxyProvider = context->contextPriv().proxyProvider(); |
Brian Salomon | 2a4f983 | 2018-03-03 22:43:43 -0500 | [diff] [blame] | 1065 | sk_sp<GrTextureProxy> proxy = proxyProvider->createProxy(desc, origin, fit, SkBudgeted::kNo); |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 1066 | |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 1067 | SkRect rect = GrTest::TestRect(random); |
| 1068 | SkRect srcRect; |
| 1069 | srcRect.fLeft = random->nextRangeScalar(0.f, proxy->width() / 2.f); |
| 1070 | srcRect.fRight = random->nextRangeScalar(0.f, proxy->width()) + proxy->width() / 2.f; |
| 1071 | srcRect.fTop = random->nextRangeScalar(0.f, proxy->height() / 2.f); |
| 1072 | srcRect.fBottom = random->nextRangeScalar(0.f, proxy->height()) + proxy->height() / 2.f; |
| 1073 | SkMatrix viewMatrix = GrTest::TestMatrixPreservesRightAngles(random); |
| 1074 | GrColor color = SkColorToPremulGrColor(random->nextU()); |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 1075 | GrSamplerState::Filter filter = (GrSamplerState::Filter)random->nextULessThan( |
| 1076 | static_cast<uint32_t>(GrSamplerState::Filter::kMipMap) + 1); |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 1077 | auto csxf = GrTest::TestColorXform(random); |
| 1078 | bool allowSRGBInputs = random->nextBool(); |
Brian Salomon | 485b8c6 | 2018-01-12 15:11:06 -0500 | [diff] [blame] | 1079 | GrAAType aaType = GrAAType::kNone; |
| 1080 | if (random->nextBool()) { |
| 1081 | aaType = (fsaaType == GrFSAAType::kUnifiedMSAA) ? GrAAType::kMSAA : GrAAType::kCoverage; |
| 1082 | } |
Brian Salomon | b80ffee | 2018-05-23 16:39:39 -0400 | [diff] [blame] | 1083 | auto constraint = random->nextBool() ? SkCanvas::kStrict_SrcRectConstraint |
| 1084 | : SkCanvas::kFast_SrcRectConstraint; |
| 1085 | return GrTextureOp::Make(std::move(proxy), filter, color, srcRect, rect, aaType, constraint, |
| 1086 | viewMatrix, std::move(csxf), allowSRGBInputs); |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 1087 | } |
| 1088 | |
| 1089 | #endif |