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