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" |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 9 | #include <new> |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 10 | #include "GrAppliedClip.h" |
Brian Salomon | 336ce7b | 2017-09-08 08:23:58 -0400 | [diff] [blame] | 11 | #include "GrCaps.h" |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 12 | #include "GrDrawOpTest.h" |
| 13 | #include "GrGeometryProcessor.h" |
Greg Daniel | 7a82edf | 2018-12-04 10:54:34 -0500 | [diff] [blame] | 14 | #include "GrGpu.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" |
Michael Ludwig | 460eb5e | 2018-10-29 11:09:29 -0400 | [diff] [blame] | 19 | #include "GrQuadPerEdgeAA.h" |
Robert Phillips | b97da53 | 2019-02-12 15:24:12 -0500 | [diff] [blame] | 20 | #include "GrRecordingContext.h" |
| 21 | #include "GrRecordingContextPriv.h" |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 22 | #include "GrResourceProvider.h" |
Greg Daniel | 7a82edf | 2018-12-04 10:54:34 -0500 | [diff] [blame] | 23 | #include "GrResourceProviderPriv.h" |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 24 | #include "GrShaderCaps.h" |
| 25 | #include "GrTexture.h" |
Brian Salomon | 336ce7b | 2017-09-08 08:23:58 -0400 | [diff] [blame] | 26 | #include "GrTexturePriv.h" |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 27 | #include "GrTextureProxy.h" |
| 28 | #include "SkGr.h" |
Brian Salomon | 336ce7b | 2017-09-08 08:23:58 -0400 | [diff] [blame] | 29 | #include "SkMathPriv.h" |
Brian Salomon | a33b67c | 2018-05-17 10:42:14 -0400 | [diff] [blame] | 30 | #include "SkMatrixPriv.h" |
Brian Salomon | b5ef1f9 | 2018-01-11 11:46:21 -0500 | [diff] [blame] | 31 | #include "SkPoint.h" |
| 32 | #include "SkPoint3.h" |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 33 | #include "SkRectPriv.h" |
Hal Canary | c640d0d | 2018-06-13 09:59:02 -0400 | [diff] [blame] | 34 | #include "SkTo.h" |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 35 | #include "glsl/GrGLSLVarying.h" |
| 36 | |
| 37 | namespace { |
| 38 | |
Michael Ludwig | 460eb5e | 2018-10-29 11:09:29 -0400 | [diff] [blame] | 39 | using Domain = GrQuadPerEdgeAA::Domain; |
Michael Ludwig | c182b94 | 2018-11-16 10:27:51 -0500 | [diff] [blame] | 40 | using VertexSpec = GrQuadPerEdgeAA::VertexSpec; |
Brian Osman | 3d139a4 | 2018-11-19 10:42:10 -0500 | [diff] [blame] | 41 | using ColorType = GrQuadPerEdgeAA::ColorType; |
Brian Salomon | b80ffee | 2018-05-23 16:39:39 -0400 | [diff] [blame] | 42 | |
Brian Salomon | 246bc3d | 2018-12-06 15:33:02 -0500 | [diff] [blame] | 43 | // if normalizing the domain then pass 1/width, 1/height, 1 for iw, ih, h. Otherwise pass |
| 44 | // 1, 1, and height. |
| 45 | static SkRect compute_domain(Domain domain, GrSamplerState::Filter filter, GrSurfaceOrigin origin, |
| 46 | const SkRect& srcRect, float iw, float ih, float h) { |
| 47 | static constexpr SkRect kLargeRect = {-100000, -100000, 1000000, 1000000}; |
Michael Ludwig | 460eb5e | 2018-10-29 11:09:29 -0400 | [diff] [blame] | 48 | if (domain == Domain::kNo) { |
| 49 | // Either the quad has no domain constraint and is batched with a domain constrained op |
| 50 | // (in which case we want a domain that doesn't restrict normalized tex coords), or the |
| 51 | // entire op doesn't use the domain, in which case the returned value is ignored. |
| 52 | return kLargeRect; |
| 53 | } |
| 54 | |
| 55 | auto ltrb = Sk4f::Load(&srcRect); |
| 56 | if (filter == GrSamplerState::Filter::kBilerp) { |
| 57 | auto rblt = SkNx_shuffle<2, 3, 0, 1>(ltrb); |
| 58 | auto whwh = (rblt - ltrb).abs(); |
| 59 | auto c = (rblt + ltrb) * 0.5f; |
| 60 | static const Sk4f kOffsets = {0.5f, 0.5f, -0.5f, -0.5f}; |
| 61 | ltrb = (whwh < 1.f).thenElse(c, ltrb + kOffsets); |
| 62 | } |
| 63 | ltrb *= Sk4f(iw, ih, iw, ih); |
| 64 | if (origin == kBottomLeft_GrSurfaceOrigin) { |
| 65 | static const Sk4f kMul = {1.f, -1.f, 1.f, -1.f}; |
Brian Salomon | 246bc3d | 2018-12-06 15:33:02 -0500 | [diff] [blame] | 66 | const Sk4f kAdd = {0.f, h, 0.f, h}; |
Michael Ludwig | 460eb5e | 2018-10-29 11:09:29 -0400 | [diff] [blame] | 67 | ltrb = SkNx_shuffle<0, 3, 2, 1>(kMul * ltrb + kAdd); |
| 68 | } |
| 69 | |
| 70 | SkRect domainRect; |
| 71 | ltrb.store(&domainRect); |
| 72 | return domainRect; |
| 73 | } |
| 74 | |
Brian Salomon | 246bc3d | 2018-12-06 15:33:02 -0500 | [diff] [blame] | 75 | // If normalizing the src quad then pass 1/width, 1/height, 1 for iw, ih, h. Otherwise pass |
| 76 | // 1, 1, and height. |
Michael Ludwig | 009b92e | 2019-02-15 16:03:53 -0500 | [diff] [blame] | 77 | static GrPerspQuad compute_src_quad_from_rect(GrSurfaceOrigin origin, const SkRect& srcRect, |
| 78 | float iw, float ih, float h) { |
Michael Ludwig | 460eb5e | 2018-10-29 11:09:29 -0400 | [diff] [blame] | 79 | // Convert the pixel-space src rectangle into normalized texture coordinates |
| 80 | SkRect texRect = { |
| 81 | iw * srcRect.fLeft, |
| 82 | ih * srcRect.fTop, |
| 83 | iw * srcRect.fRight, |
| 84 | ih * srcRect.fBottom |
| 85 | }; |
| 86 | if (origin == kBottomLeft_GrSurfaceOrigin) { |
Brian Salomon | 246bc3d | 2018-12-06 15:33:02 -0500 | [diff] [blame] | 87 | texRect.fTop = h - texRect.fTop; |
| 88 | texRect.fBottom = h - texRect.fBottom; |
Michael Ludwig | 460eb5e | 2018-10-29 11:09:29 -0400 | [diff] [blame] | 89 | } |
Michael Ludwig | e9c57d3 | 2019-02-13 13:39:39 -0500 | [diff] [blame] | 90 | return GrPerspQuad(texRect); |
Michael Ludwig | 460eb5e | 2018-10-29 11:09:29 -0400 | [diff] [blame] | 91 | } |
Michael Ludwig | 009b92e | 2019-02-15 16:03:53 -0500 | [diff] [blame] | 92 | // Normalizes logical src coords and corrects for origin |
| 93 | static GrPerspQuad compute_src_quad(GrSurfaceOrigin origin, const GrPerspQuad& srcQuad, |
| 94 | float iw, float ih, float h) { |
| 95 | // The src quad should not have any perspective |
| 96 | SkASSERT(!srcQuad.hasPerspective()); |
| 97 | Sk4f xs = srcQuad.x4f() * iw; |
| 98 | Sk4f ys = srcQuad.y4f() * ih; |
| 99 | if (origin == kBottomLeft_GrSurfaceOrigin) { |
| 100 | ys = h - ys; |
| 101 | } |
| 102 | return GrPerspQuad(xs, ys); |
| 103 | } |
Michael Ludwig | 460eb5e | 2018-10-29 11:09:29 -0400 | [diff] [blame] | 104 | |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 105 | /** |
| 106 | * Op that implements GrTextureOp::Make. It draws textured quads. Each quad can modulate against a |
| 107 | * the texture by color. The blend with the destination is always src-over. The edges are non-AA. |
| 108 | */ |
| 109 | class TextureOp final : public GrMeshDrawOp { |
| 110 | public: |
Robert Phillips | b97da53 | 2019-02-12 15:24:12 -0500 | [diff] [blame] | 111 | static std::unique_ptr<GrDrawOp> Make(GrRecordingContext* context, |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 112 | sk_sp<GrTextureProxy> proxy, |
| 113 | GrSamplerState::Filter filter, |
Brian Osman | 3d139a4 | 2018-11-19 10:42:10 -0500 | [diff] [blame] | 114 | const SkPMColor4f& color, |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 115 | const SkRect& srcRect, |
| 116 | const SkRect& dstRect, |
| 117 | GrAAType aaType, |
Brian Salomon | 2213ee9 | 2018-10-02 10:44:21 -0400 | [diff] [blame] | 118 | GrQuadAAFlags aaFlags, |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 119 | SkCanvas::SrcRectConstraint constraint, |
Brian Osman | 2b23c4b | 2018-06-01 12:25:08 -0400 | [diff] [blame] | 120 | const SkMatrix& viewMatrix, |
Brian Osman | 3d139a4 | 2018-11-19 10:42:10 -0500 | [diff] [blame] | 121 | sk_sp<GrColorSpaceXform> textureColorSpaceXform) { |
Michael Ludwig | 009b92e | 2019-02-15 16:03:53 -0500 | [diff] [blame] | 122 | GrPerspQuad dstQuad = GrPerspQuad::MakeFromRect(dstRect, viewMatrix); |
| 123 | GrQuadType dstQuadType = GrQuadTypeForTransformedRect(viewMatrix); |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 124 | |
Michael Ludwig | 009b92e | 2019-02-15 16:03:53 -0500 | [diff] [blame] | 125 | if (dstQuadType == GrQuadType::kRect) { |
| 126 | // Disable filtering if possible (note AA optimizations for rects are automatically |
| 127 | // handled above in GrResolveAATypeForQuad). |
| 128 | if (filter != GrSamplerState::Filter::kNearest && |
| 129 | !GrTextureOp::GetFilterHasEffect(viewMatrix, srcRect, dstRect)) { |
| 130 | filter = GrSamplerState::Filter::kNearest; |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | GrOpMemoryPool* pool = context->priv().opMemoryPool(); |
| 135 | // srcRect provides both local coords and domain (if needed), so use nullptr for srcQuad |
Brian Salomon | 2213ee9 | 2018-10-02 10:44:21 -0400 | [diff] [blame] | 136 | return pool->allocate<TextureOp>( |
Michael Ludwig | 009b92e | 2019-02-15 16:03:53 -0500 | [diff] [blame] | 137 | std::move(proxy), filter, color, dstQuad, dstQuadType, srcRect, constraint, |
| 138 | nullptr, GrQuadType::kRect, aaType, aaFlags, std::move(textureColorSpaceXform)); |
| 139 | } |
| 140 | static std::unique_ptr<GrDrawOp> Make(GrRecordingContext* context, |
| 141 | sk_sp<GrTextureProxy> proxy, |
| 142 | GrSamplerState::Filter filter, |
| 143 | const SkPMColor4f& color, |
| 144 | const SkPoint srcQuad[4], |
| 145 | const SkPoint dstQuad[4], |
| 146 | GrAAType aaType, |
| 147 | GrQuadAAFlags aaFlags, |
| 148 | const SkRect* domain, |
| 149 | const SkMatrix& viewMatrix, |
| 150 | sk_sp<GrColorSpaceXform> textureColorSpaceXform) { |
| 151 | GrPerspQuad grDstQuad = GrPerspQuad::MakeFromSkQuad(dstQuad, viewMatrix); |
Michael Ludwig | 97b9442 | 2019-04-09 10:42:39 -0400 | [diff] [blame] | 152 | GrQuadType dstQuadType = GrQuadTypeForPoints(dstQuad, viewMatrix); |
Michael Ludwig | 009b92e | 2019-02-15 16:03:53 -0500 | [diff] [blame] | 153 | GrPerspQuad grSrcQuad = GrPerspQuad::MakeFromSkQuad(srcQuad, SkMatrix::I()); |
Michael Ludwig | 97b9442 | 2019-04-09 10:42:39 -0400 | [diff] [blame] | 154 | GrQuadType srcQuadType = GrQuadTypeForPoints(srcQuad, SkMatrix::I()); |
Michael Ludwig | 009b92e | 2019-02-15 16:03:53 -0500 | [diff] [blame] | 155 | |
| 156 | // If constraint remains fast, the value in srcRect will be ignored since srcQuads provides |
| 157 | // the local coordinates and a domain won't be used. |
| 158 | SkRect srcRect = SkRect::MakeEmpty(); |
| 159 | SkCanvas::SrcRectConstraint constraint = SkCanvas::kFast_SrcRectConstraint; |
| 160 | if (domain) { |
| 161 | srcRect = *domain; |
| 162 | constraint = SkCanvas::kStrict_SrcRectConstraint; |
| 163 | } |
| 164 | |
| 165 | GrOpMemoryPool* pool = context->priv().opMemoryPool(); |
| 166 | // Pass domain as srcRect if provided, but send srcQuad as a GrPerspQuad for local coords |
| 167 | return pool->allocate<TextureOp>( |
| 168 | std::move(proxy), filter, color, grDstQuad, dstQuadType, srcRect, constraint, |
Michael Ludwig | 97b9442 | 2019-04-09 10:42:39 -0400 | [diff] [blame] | 169 | &grSrcQuad, srcQuadType, aaType, aaFlags, |
Michael Ludwig | 009b92e | 2019-02-15 16:03:53 -0500 | [diff] [blame] | 170 | std::move(textureColorSpaceXform)); |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 171 | } |
Robert Phillips | b97da53 | 2019-02-12 15:24:12 -0500 | [diff] [blame] | 172 | static std::unique_ptr<GrDrawOp> Make(GrRecordingContext* context, |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 173 | const GrRenderTargetContext::TextureSetEntry set[], |
Brian Salomon | d003d22 | 2018-11-26 13:25:05 -0500 | [diff] [blame] | 174 | int cnt, GrSamplerState::Filter filter, GrAAType aaType, |
Michael Ludwig | 31ba718 | 2019-04-03 10:38:06 -0400 | [diff] [blame] | 175 | SkCanvas::SrcRectConstraint constraint, |
Brian Salomon | d003d22 | 2018-11-26 13:25:05 -0500 | [diff] [blame] | 176 | const SkMatrix& viewMatrix, |
Brian Osman | 3d139a4 | 2018-11-19 10:42:10 -0500 | [diff] [blame] | 177 | sk_sp<GrColorSpaceXform> textureColorSpaceXform) { |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 178 | size_t size = sizeof(TextureOp) + sizeof(Proxy) * (cnt - 1); |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 179 | GrOpMemoryPool* pool = context->priv().opMemoryPool(); |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 180 | void* mem = pool->allocate(size); |
Michael Ludwig | 31ba718 | 2019-04-03 10:38:06 -0400 | [diff] [blame] | 181 | return std::unique_ptr<GrDrawOp>(new (mem) TextureOp( |
| 182 | set, cnt, filter, aaType, constraint, viewMatrix, |
| 183 | std::move(textureColorSpaceXform))); |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 184 | } |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 185 | |
Brian Salomon | 336ce7b | 2017-09-08 08:23:58 -0400 | [diff] [blame] | 186 | ~TextureOp() override { |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 187 | for (unsigned p = 0; p < fProxyCnt; ++p) { |
| 188 | if (fFinalized) { |
| 189 | fProxies[p].fProxy->completedRead(); |
| 190 | } else { |
| 191 | fProxies[p].fProxy->unref(); |
| 192 | } |
Brian Salomon | 336ce7b | 2017-09-08 08:23:58 -0400 | [diff] [blame] | 193 | } |
| 194 | } |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 195 | |
| 196 | const char* name() const override { return "TextureOp"; } |
| 197 | |
Brian Salomon | 7d94bb5 | 2018-10-12 14:37:19 -0400 | [diff] [blame] | 198 | void visitProxies(const VisitProxyFunc& func, VisitorType visitor) const override { |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 199 | for (unsigned p = 0; p < fProxyCnt; ++p) { |
| 200 | func(fProxies[p].fProxy); |
| 201 | } |
| 202 | } |
Robert Phillips | b493eeb | 2017-09-13 13:10:52 -0400 | [diff] [blame] | 203 | |
Brian Osman | 9a390ac | 2018-11-12 09:47:48 -0500 | [diff] [blame] | 204 | #ifdef SK_DEBUG |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 205 | SkString dumpInfo() const override { |
| 206 | SkString str; |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 207 | str.appendf("# draws: %d\n", fQuads.count()); |
| 208 | int q = 0; |
| 209 | for (unsigned p = 0; p < fProxyCnt; ++p) { |
| 210 | str.appendf("Proxy ID: %d, Filter: %d\n", fProxies[p].fProxy->uniqueID().asUInt(), |
| 211 | static_cast<int>(fFilter)); |
| 212 | for (int i = 0; i < fProxies[p].fQuadCnt; ++i, ++q) { |
Michael Ludwig | c96fc37 | 2019-01-08 15:46:15 -0500 | [diff] [blame] | 213 | GrPerspQuad quad = fQuads[q]; |
| 214 | const ColorDomainAndAA& info = fQuads.metadata(i); |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 215 | str.appendf( |
| 216 | "%d: Color: 0x%08x, TexRect [L: %.2f, T: %.2f, R: %.2f, B: %.2f] " |
| 217 | "Quad [(%.2f, %.2f), (%.2f, %.2f), (%.2f, %.2f), (%.2f, %.2f)]\n", |
Michael Ludwig | c96fc37 | 2019-01-08 15:46:15 -0500 | [diff] [blame] | 218 | i, info.fColor.toBytes_RGBA(), info.fSrcRect.fLeft, info.fSrcRect.fTop, |
| 219 | info.fSrcRect.fRight, info.fSrcRect.fBottom, quad.point(0).fX, |
| 220 | quad.point(0).fY, quad.point(1).fX, quad.point(1).fY, |
| 221 | quad.point(2).fX, quad.point(2).fY, quad.point(3).fX, |
| 222 | quad.point(3).fY); |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 223 | } |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 224 | } |
| 225 | str += INHERITED::dumpInfo(); |
| 226 | return str; |
| 227 | } |
Brian Osman | 9a390ac | 2018-11-12 09:47:48 -0500 | [diff] [blame] | 228 | #endif |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 229 | |
Brian Osman | 5ced0bf | 2019-03-15 10:15:29 -0400 | [diff] [blame] | 230 | GrProcessorSet::Analysis finalize( |
Brian Osman | 8fa7ab4 | 2019-03-18 10:22:42 -0400 | [diff] [blame] | 231 | const GrCaps& caps, const GrAppliedClip*, GrFSAAType, GrClampType clampType) override { |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 232 | SkASSERT(!fFinalized); |
| 233 | fFinalized = true; |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 234 | for (unsigned p = 0; p < fProxyCnt; ++p) { |
| 235 | fProxies[p].fProxy->addPendingRead(); |
| 236 | fProxies[p].fProxy->unref(); |
| 237 | } |
Brian Osman | 8fa7ab4 | 2019-03-18 10:22:42 -0400 | [diff] [blame] | 238 | fColorType = static_cast<unsigned>(ColorType::kNone); |
| 239 | for (int q = 0; q < fQuads.count(); ++q) { |
| 240 | const ColorDomainAndAA& info = fQuads.metadata(q); |
| 241 | auto colorType = GrQuadPerEdgeAA::MinColorType(info.fColor, clampType, caps); |
| 242 | fColorType = SkTMax(fColorType, static_cast<unsigned>(colorType)); |
| 243 | } |
Chris Dalton | 4b62aed | 2019-01-15 11:53:00 -0700 | [diff] [blame] | 244 | return GrProcessorSet::EmptySetAnalysis(); |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 245 | } |
| 246 | |
Brian Salomon | 485b8c6 | 2018-01-12 15:11:06 -0500 | [diff] [blame] | 247 | FixedFunctionFlags fixedFunctionFlags() const override { |
| 248 | return this->aaType() == GrAAType::kMSAA ? FixedFunctionFlags::kUsesHWAA |
| 249 | : FixedFunctionFlags::kNone; |
| 250 | } |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 251 | |
| 252 | DEFINE_OP_CLASS_ID |
| 253 | |
| 254 | private: |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 255 | friend class ::GrOpMemoryPool; |
Brian Salomon | 762d5e7 | 2017-12-01 10:25:08 -0500 | [diff] [blame] | 256 | |
Michael Ludwig | 009b92e | 2019-02-15 16:03:53 -0500 | [diff] [blame] | 257 | // dstQuad and dstQuadType should be the geometry transformed by the view matrix. |
| 258 | // srcRect represents original src rect and will be used as the domain when constraint is strict |
| 259 | // If srcQuad is provided, it will be used for the local coords instead of srcRect, although |
| 260 | // srcRect will still specify the domain constraint if needed. |
Brian Osman | 3d139a4 | 2018-11-19 10:42:10 -0500 | [diff] [blame] | 261 | TextureOp(sk_sp<GrTextureProxy> proxy, GrSamplerState::Filter filter, const SkPMColor4f& color, |
Michael Ludwig | 009b92e | 2019-02-15 16:03:53 -0500 | [diff] [blame] | 262 | const GrPerspQuad& dstQuad, GrQuadType dstQuadType, |
| 263 | const SkRect& srcRect, SkCanvas::SrcRectConstraint constraint, |
| 264 | const GrPerspQuad* srcQuad, GrQuadType srcQuadType, GrAAType aaType, |
| 265 | GrQuadAAFlags aaFlags, sk_sp<GrColorSpaceXform> textureColorSpaceXform) |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 266 | : INHERITED(ClassID()) |
Brian Osman | 3ebd354 | 2018-07-30 14:36:53 -0400 | [diff] [blame] | 267 | , fTextureColorSpaceXform(std::move(textureColorSpaceXform)) |
Brian Salomon | 0087c83 | 2018-10-15 14:48:20 -0400 | [diff] [blame] | 268 | , fFilter(static_cast<unsigned>(filter)) |
Brian Osman | 2b23c4b | 2018-06-01 12:25:08 -0400 | [diff] [blame] | 269 | , fFinalized(0) { |
Michael Ludwig | 6bee776 | 2018-10-19 09:50:36 -0400 | [diff] [blame] | 270 | // Clean up disparities between the overall aa type and edge configuration and apply |
| 271 | // optimizations based on the rect and matrix when appropriate |
Michael Ludwig | 009b92e | 2019-02-15 16:03:53 -0500 | [diff] [blame] | 272 | GrResolveAATypeForQuad(aaType, aaFlags, dstQuad, dstQuadType, &aaType, &aaFlags); |
Michael Ludwig | 6bee776 | 2018-10-19 09:50:36 -0400 | [diff] [blame] | 273 | fAAType = static_cast<unsigned>(aaType); |
| 274 | |
Brian Salomon | f170904 | 2018-10-03 11:57:00 -0400 | [diff] [blame] | 275 | // We expect our caller to have already caught this optimization. |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 276 | SkASSERT(!srcRect.contains(proxy->getWorstCaseBoundsRect()) || |
Brian Salomon | f170904 | 2018-10-03 11:57:00 -0400 | [diff] [blame] | 277 | constraint == SkCanvas::kFast_SrcRectConstraint); |
Michael Ludwig | 009b92e | 2019-02-15 16:03:53 -0500 | [diff] [blame] | 278 | |
Brian Salomon | f09abc5 | 2018-10-03 15:59:04 -0400 | [diff] [blame] | 279 | // We may have had a strict constraint with nearest filter solely due to possible AA bloat. |
| 280 | // If we don't have (or determined we don't need) coverage AA then we can skip using a |
| 281 | // domain. |
| 282 | if (constraint == SkCanvas::kStrict_SrcRectConstraint && |
Brian Salomon | 0087c83 | 2018-10-15 14:48:20 -0400 | [diff] [blame] | 283 | this->filter() == GrSamplerState::Filter::kNearest && |
Michael Ludwig | 6bee776 | 2018-10-19 09:50:36 -0400 | [diff] [blame] | 284 | aaType != GrAAType::kCoverage) { |
Brian Salomon | f09abc5 | 2018-10-03 15:59:04 -0400 | [diff] [blame] | 285 | constraint = SkCanvas::kFast_SrcRectConstraint; |
| 286 | } |
Michael Ludwig | c96fc37 | 2019-01-08 15:46:15 -0500 | [diff] [blame] | 287 | |
| 288 | Domain domain = constraint == SkCanvas::kStrict_SrcRectConstraint ? Domain::kYes |
| 289 | : Domain::kNo; |
Michael Ludwig | 009b92e | 2019-02-15 16:03:53 -0500 | [diff] [blame] | 290 | // Initially, if srcQuad is provided it will always be at index 0 of fSrcQuads |
| 291 | fQuads.push_back(dstQuad, dstQuadType, {color, srcRect, srcQuad ? 0 : -1, domain, aaFlags}); |
| 292 | if (srcQuad) { |
| 293 | fSrcQuads.push_back(*srcQuad, srcQuadType); |
| 294 | } |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 295 | fProxyCnt = 1; |
| 296 | fProxies[0] = {proxy.release(), 1}; |
Michael Ludwig | 009b92e | 2019-02-15 16:03:53 -0500 | [diff] [blame] | 297 | auto bounds = dstQuad.bounds(dstQuadType); |
Michael Ludwig | 6bee776 | 2018-10-19 09:50:36 -0400 | [diff] [blame] | 298 | this->setBounds(bounds, HasAABloat(aaType == GrAAType::kCoverage), IsZeroArea::kNo); |
Michael Ludwig | c96fc37 | 2019-01-08 15:46:15 -0500 | [diff] [blame] | 299 | fDomain = static_cast<unsigned>(domain); |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 300 | } |
| 301 | TextureOp(const GrRenderTargetContext::TextureSetEntry set[], int cnt, |
Michael Ludwig | 31ba718 | 2019-04-03 10:38:06 -0400 | [diff] [blame] | 302 | GrSamplerState::Filter filter, GrAAType aaType, |
| 303 | SkCanvas::SrcRectConstraint constraint, const SkMatrix& viewMatrix, |
Brian Salomon | d003d22 | 2018-11-26 13:25:05 -0500 | [diff] [blame] | 304 | sk_sp<GrColorSpaceXform> textureColorSpaceXform) |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 305 | : INHERITED(ClassID()) |
| 306 | , fTextureColorSpaceXform(std::move(textureColorSpaceXform)) |
Brian Salomon | 0087c83 | 2018-10-15 14:48:20 -0400 | [diff] [blame] | 307 | , fFilter(static_cast<unsigned>(filter)) |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 308 | , fFinalized(0) { |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 309 | fProxyCnt = SkToUInt(cnt); |
| 310 | SkRect bounds = SkRectPriv::MakeLargestInverted(); |
Michael Ludwig | 6bee776 | 2018-10-19 09:50:36 -0400 | [diff] [blame] | 311 | GrAAType overallAAType = GrAAType::kNone; // aa type maximally compatible with all dst rects |
Brian Salomon | 0087c83 | 2018-10-15 14:48:20 -0400 | [diff] [blame] | 312 | bool mustFilter = false; |
Michael Ludwig | 7ae2ab5 | 2019-03-05 16:00:20 -0500 | [diff] [blame] | 313 | // Most dst rects are transformed by the same view matrix, so their quad types start |
| 314 | // identical, unless an entry provides a dstClip or additional transform that changes it. |
| 315 | // The quad list will automatically adapt to that. |
| 316 | fQuads.reserve(cnt, GrQuadTypeForTransformedRect(viewMatrix)); |
Brian Salomon | 1d83542 | 2019-03-13 16:11:44 -0400 | [diff] [blame] | 317 | bool allOpaque = true; |
Michael Ludwig | 31ba718 | 2019-04-03 10:38:06 -0400 | [diff] [blame] | 318 | Domain netDomain = Domain::kNo; |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 319 | for (unsigned p = 0; p < fProxyCnt; ++p) { |
| 320 | fProxies[p].fProxy = SkRef(set[p].fProxy.get()); |
| 321 | fProxies[p].fQuadCnt = 1; |
| 322 | SkASSERT(fProxies[p].fProxy->textureType() == fProxies[0].fProxy->textureType()); |
| 323 | SkASSERT(fProxies[p].fProxy->config() == fProxies[0].fProxy->config()); |
Michael Ludwig | ce62dec | 2019-02-19 11:48:46 -0500 | [diff] [blame] | 324 | |
Michael Ludwig | 7ae2ab5 | 2019-03-05 16:00:20 -0500 | [diff] [blame] | 325 | SkMatrix ctm = viewMatrix; |
| 326 | if (set[p].fPreViewMatrix) { |
| 327 | ctm.preConcat(*set[p].fPreViewMatrix); |
| 328 | } |
| 329 | |
Michael Ludwig | ce62dec | 2019-02-19 11:48:46 -0500 | [diff] [blame] | 330 | // Use dstRect unless dstClip is provided, which is assumed to be a quad |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 331 | auto quad = set[p].fDstClipQuad == nullptr ? |
Michael Ludwig | 7ae2ab5 | 2019-03-05 16:00:20 -0500 | [diff] [blame] | 332 | GrPerspQuad::MakeFromRect(set[p].fDstRect, ctm) : |
| 333 | GrPerspQuad::MakeFromSkQuad(set[p].fDstClipQuad, ctm); |
Michael Ludwig | 97b9442 | 2019-04-09 10:42:39 -0400 | [diff] [blame] | 334 | GrQuadType quadType = |
| 335 | set[p].fDstClipQuad ? GrQuadTypeForPoints(set[p].fDstClipQuad, ctm) |
| 336 | : GrQuadTypeForTransformedRect(ctm); |
Michael Ludwig | ce62dec | 2019-02-19 11:48:46 -0500 | [diff] [blame] | 337 | |
Michael Ludwig | c96fc37 | 2019-01-08 15:46:15 -0500 | [diff] [blame] | 338 | bounds.joinPossiblyEmptyRect(quad.bounds(quadType)); |
Michael Ludwig | 6bee776 | 2018-10-19 09:50:36 -0400 | [diff] [blame] | 339 | GrQuadAAFlags aaFlags; |
| 340 | // Don't update the overall aaType, might be inappropriate for some of the quads |
| 341 | GrAAType aaForQuad; |
| 342 | GrResolveAATypeForQuad(aaType, set[p].fAAFlags, quad, quadType, &aaForQuad, &aaFlags); |
| 343 | // Resolve sets aaForQuad to aaType or None, there is never a change between aa methods |
| 344 | SkASSERT(aaForQuad == GrAAType::kNone || aaForQuad == aaType); |
| 345 | if (overallAAType == GrAAType::kNone && aaForQuad != GrAAType::kNone) { |
| 346 | overallAAType = aaType; |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 347 | } |
Brian Salomon | 0087c83 | 2018-10-15 14:48:20 -0400 | [diff] [blame] | 348 | if (!mustFilter && this->filter() != GrSamplerState::Filter::kNearest) { |
Michael Ludwig | c182b94 | 2018-11-16 10:27:51 -0500 | [diff] [blame] | 349 | mustFilter = quadType != GrQuadType::kRect || |
Michael Ludwig | 7ae2ab5 | 2019-03-05 16:00:20 -0500 | [diff] [blame] | 350 | GrTextureOp::GetFilterHasEffect(ctm, set[p].fSrcRect, |
Michael Ludwig | a3c45c7 | 2019-01-17 17:26:48 -0500 | [diff] [blame] | 351 | set[p].fDstRect); |
Brian Salomon | 0087c83 | 2018-10-15 14:48:20 -0400 | [diff] [blame] | 352 | } |
Michael Ludwig | 31ba718 | 2019-04-03 10:38:06 -0400 | [diff] [blame] | 353 | Domain domainForQuad = Domain::kNo; |
| 354 | if (constraint == SkCanvas::kStrict_SrcRectConstraint) { |
| 355 | // Check (briefly) if the strict constraint is needed for this set entry |
| 356 | if (!set[p].fSrcRect.contains(fProxies[p].fProxy->getWorstCaseBoundsRect()) && |
| 357 | (mustFilter || aaForQuad == GrAAType::kCoverage)) { |
| 358 | // Can't rely on hardware clamping and the draw will access outer texels |
| 359 | // for AA and/or bilerp |
| 360 | netDomain = Domain::kYes; |
| 361 | domainForQuad = Domain::kYes; |
| 362 | } |
| 363 | } |
Brian Salomon | d003d22 | 2018-11-26 13:25:05 -0500 | [diff] [blame] | 364 | float alpha = SkTPin(set[p].fAlpha, 0.f, 1.f); |
Brian Salomon | 1d83542 | 2019-03-13 16:11:44 -0400 | [diff] [blame] | 365 | allOpaque &= (1.f == alpha); |
Brian Salomon | d003d22 | 2018-11-26 13:25:05 -0500 | [diff] [blame] | 366 | SkPMColor4f color{alpha, alpha, alpha, alpha}; |
Michael Ludwig | ce62dec | 2019-02-19 11:48:46 -0500 | [diff] [blame] | 367 | int srcQuadIndex = -1; |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 368 | if (set[p].fDstClipQuad) { |
Michael Ludwig | ce62dec | 2019-02-19 11:48:46 -0500 | [diff] [blame] | 369 | // Derive new source coordinates that match dstClip's relative locations in dstRect, |
| 370 | // but with respect to srcRect |
| 371 | SkPoint srcQuad[4]; |
Michael Ludwig | 1433cfd | 2019-02-27 17:12:30 -0500 | [diff] [blame] | 372 | GrMapRectPoints(set[p].fDstRect, set[p].fSrcRect, set[p].fDstClipQuad, srcQuad, 4); |
Michael Ludwig | ce62dec | 2019-02-19 11:48:46 -0500 | [diff] [blame] | 373 | fSrcQuads.push_back(GrPerspQuad::MakeFromSkQuad(srcQuad, SkMatrix::I()), |
Michael Ludwig | 97b9442 | 2019-04-09 10:42:39 -0400 | [diff] [blame] | 374 | GrQuadTypeForPoints(srcQuad, SkMatrix::I())); |
Michael Ludwig | ce62dec | 2019-02-19 11:48:46 -0500 | [diff] [blame] | 375 | srcQuadIndex = fSrcQuads.count() - 1; |
| 376 | } |
| 377 | fQuads.push_back(quad, quadType, |
Michael Ludwig | 31ba718 | 2019-04-03 10:38:06 -0400 | [diff] [blame] | 378 | {color, set[p].fSrcRect, srcQuadIndex, domainForQuad, aaFlags}); |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 379 | } |
Michael Ludwig | 6bee776 | 2018-10-19 09:50:36 -0400 | [diff] [blame] | 380 | fAAType = static_cast<unsigned>(overallAAType); |
Brian Salomon | 0087c83 | 2018-10-15 14:48:20 -0400 | [diff] [blame] | 381 | if (!mustFilter) { |
| 382 | fFilter = static_cast<unsigned>(GrSamplerState::Filter::kNearest); |
| 383 | } |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 384 | this->setBounds(bounds, HasAABloat(this->aaType() == GrAAType::kCoverage), IsZeroArea::kNo); |
Michael Ludwig | 31ba718 | 2019-04-03 10:38:06 -0400 | [diff] [blame] | 385 | fDomain = static_cast<unsigned>(netDomain); |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 386 | } |
| 387 | |
Brian Salomon | 574d616 | 2018-11-19 16:57:25 -0500 | [diff] [blame] | 388 | void tess(void* v, const VertexSpec& spec, const GrTextureProxy* proxy, int start, |
| 389 | int cnt) const { |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 390 | TRACE_EVENT0("skia", TRACE_FUNC); |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 391 | auto origin = proxy->origin(); |
| 392 | const auto* texture = proxy->peekTexture(); |
Brian Salomon | 246bc3d | 2018-12-06 15:33:02 -0500 | [diff] [blame] | 393 | float iw, ih, h; |
| 394 | if (proxy->textureType() == GrTextureType::kRectangle) { |
| 395 | iw = ih = 1.f; |
| 396 | h = texture->height(); |
| 397 | } else { |
| 398 | iw = 1.f / texture->width(); |
| 399 | ih = 1.f / texture->height(); |
| 400 | h = 1.f; |
| 401 | } |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 402 | |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 403 | for (int i = start; i < start + cnt; ++i) { |
Michael Ludwig | c96fc37 | 2019-01-08 15:46:15 -0500 | [diff] [blame] | 404 | const GrPerspQuad& device = fQuads[i]; |
| 405 | const ColorDomainAndAA& info = fQuads.metadata(i); |
| 406 | |
Michael Ludwig | 009b92e | 2019-02-15 16:03:53 -0500 | [diff] [blame] | 407 | GrPerspQuad srcQuad = info.fSrcQuadIndex >= 0 ? |
| 408 | compute_src_quad(origin, fSrcQuads[info.fSrcQuadIndex], iw, ih, h) : |
| 409 | compute_src_quad_from_rect(origin, info.fSrcRect, iw, ih, h); |
Brian Salomon | 246bc3d | 2018-12-06 15:33:02 -0500 | [diff] [blame] | 410 | SkRect domain = |
Michael Ludwig | c96fc37 | 2019-01-08 15:46:15 -0500 | [diff] [blame] | 411 | compute_domain(info.domain(), this->filter(), origin, info.fSrcRect, iw, ih, h); |
| 412 | v = GrQuadPerEdgeAA::Tessellate(v, spec, device, info.fColor, srcQuad, domain, |
| 413 | info.aaFlags()); |
Brian Salomon | 17031a7 | 2018-05-22 14:14:07 -0400 | [diff] [blame] | 414 | } |
| 415 | } |
| 416 | |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 417 | void onPrepareDraws(Target* target) override { |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 418 | TRACE_EVENT0("skia", TRACE_FUNC); |
Michael Ludwig | f995c05 | 2018-11-26 15:24:29 -0500 | [diff] [blame] | 419 | GrQuadType quadType = GrQuadType::kRect; |
Michael Ludwig | 009b92e | 2019-02-15 16:03:53 -0500 | [diff] [blame] | 420 | GrQuadType srcQuadType = GrQuadType::kRect; |
Brian Salomon | f723264 | 2018-09-19 08:58:08 -0400 | [diff] [blame] | 421 | Domain domain = Domain::kNo; |
Brian Salomon | 1d83542 | 2019-03-13 16:11:44 -0400 | [diff] [blame] | 422 | ColorType colorType = ColorType::kNone; |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 423 | int numProxies = 0; |
Brian Salomon | 4b8178f | 2018-10-12 13:18:27 -0400 | [diff] [blame] | 424 | int numTotalQuads = 0; |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 425 | auto textureType = fProxies[0].fProxy->textureType(); |
| 426 | auto config = fProxies[0].fProxy->config(); |
Brian Salomon | ae7d770 | 2018-10-14 15:05:45 -0400 | [diff] [blame] | 427 | GrAAType aaType = this->aaType(); |
Brian Salomon | f723264 | 2018-09-19 08:58:08 -0400 | [diff] [blame] | 428 | for (const auto& op : ChainRange<TextureOp>(this)) { |
Michael Ludwig | c96fc37 | 2019-01-08 15:46:15 -0500 | [diff] [blame] | 429 | if (op.fQuads.quadType() > quadType) { |
| 430 | quadType = op.fQuads.quadType(); |
Michael Ludwig | f995c05 | 2018-11-26 15:24:29 -0500 | [diff] [blame] | 431 | } |
Michael Ludwig | 009b92e | 2019-02-15 16:03:53 -0500 | [diff] [blame] | 432 | if (op.fSrcQuads.quadType() > srcQuadType) { |
| 433 | // Should only become more general if there are quads to use instead of fSrcRect |
| 434 | SkASSERT(op.fSrcQuads.count() > 0); |
| 435 | srcQuadType = op.fSrcQuads.quadType(); |
| 436 | } |
Brian Salomon | f723264 | 2018-09-19 08:58:08 -0400 | [diff] [blame] | 437 | if (op.fDomain) { |
| 438 | domain = Domain::kYes; |
| 439 | } |
Brian Salomon | 1d83542 | 2019-03-13 16:11:44 -0400 | [diff] [blame] | 440 | colorType = SkTMax(colorType, static_cast<ColorType>(op.fColorType)); |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 441 | numProxies += op.fProxyCnt; |
| 442 | for (unsigned p = 0; p < op.fProxyCnt; ++p) { |
Brian Salomon | 4b8178f | 2018-10-12 13:18:27 -0400 | [diff] [blame] | 443 | numTotalQuads += op.fProxies[p].fQuadCnt; |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 444 | auto* proxy = op.fProxies[p].fProxy; |
Robert Phillips | 12c4629 | 2019-04-23 07:36:17 -0400 | [diff] [blame^] | 445 | if (!proxy->isInstantiated()) { |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 446 | return; |
| 447 | } |
| 448 | SkASSERT(proxy->config() == config); |
| 449 | SkASSERT(proxy->textureType() == textureType); |
Brian Salomon | f723264 | 2018-09-19 08:58:08 -0400 | [diff] [blame] | 450 | } |
Brian Salomon | ae7d770 | 2018-10-14 15:05:45 -0400 | [diff] [blame] | 451 | if (op.aaType() == GrAAType::kCoverage) { |
| 452 | SkASSERT(aaType == GrAAType::kCoverage || aaType == GrAAType::kNone); |
| 453 | aaType = GrAAType::kCoverage; |
| 454 | } |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 455 | } |
Brian Salomon | 336ce7b | 2017-09-08 08:23:58 -0400 | [diff] [blame] | 456 | |
Brian Salomon | 1d83542 | 2019-03-13 16:11:44 -0400 | [diff] [blame] | 457 | VertexSpec vertexSpec(quadType, colorType, srcQuadType, /* hasLocal */ true, domain, aaType, |
Michael Ludwig | 93aeba0 | 2018-12-21 09:50:31 -0500 | [diff] [blame] | 458 | /* alpha as coverage */ true); |
Michael Ludwig | c182b94 | 2018-11-16 10:27:51 -0500 | [diff] [blame] | 459 | |
Greg Daniel | 7a82edf | 2018-12-04 10:54:34 -0500 | [diff] [blame] | 460 | GrSamplerState samplerState = GrSamplerState(GrSamplerState::WrapMode::kClamp, |
| 461 | this->filter()); |
| 462 | GrGpu* gpu = target->resourceProvider()->priv().gpu(); |
| 463 | uint32_t extraSamplerKey = gpu->getExtraSamplerKeyForProgram( |
| 464 | samplerState, fProxies[0].fProxy->backendFormat()); |
| 465 | |
Michael Ludwig | 467994d | 2018-12-03 14:58:31 +0000 | [diff] [blame] | 466 | sk_sp<GrGeometryProcessor> gp = GrQuadPerEdgeAA::MakeTexturedProcessor( |
| 467 | vertexSpec, *target->caps().shaderCaps(), |
Greg Daniel | 7a82edf | 2018-12-04 10:54:34 -0500 | [diff] [blame] | 468 | textureType, config, samplerState, extraSamplerKey, |
| 469 | std::move(fTextureColorSpaceXform)); |
| 470 | |
Brian Salomon | f723264 | 2018-09-19 08:58:08 -0400 | [diff] [blame] | 471 | // We'll use a dynamic state array for the GP textures when there are multiple ops. |
| 472 | // Otherwise, we use fixed dynamic state to specify the single op's proxy. |
| 473 | GrPipeline::DynamicStateArrays* dynamicStateArrays = nullptr; |
| 474 | GrPipeline::FixedDynamicState* fixedDynamicState; |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 475 | if (numProxies > 1) { |
| 476 | dynamicStateArrays = target->allocDynamicStateArrays(numProxies, 1, false); |
Chris Dalton | 07cdcfc9 | 2019-02-26 11:13:22 -0700 | [diff] [blame] | 477 | fixedDynamicState = target->makeFixedDynamicState(0); |
Brian Salomon | f723264 | 2018-09-19 08:58:08 -0400 | [diff] [blame] | 478 | } else { |
Chris Dalton | 07cdcfc9 | 2019-02-26 11:13:22 -0700 | [diff] [blame] | 479 | fixedDynamicState = target->makeFixedDynamicState(1); |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 480 | fixedDynamicState->fPrimitiveProcessorTextures[0] = fProxies[0].fProxy; |
Brian Salomon | f723264 | 2018-09-19 08:58:08 -0400 | [diff] [blame] | 481 | } |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 482 | |
Michael Ludwig | c182b94 | 2018-11-16 10:27:51 -0500 | [diff] [blame] | 483 | size_t vertexSize = gp->vertexStride(); |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 484 | |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 485 | GrMesh* meshes = target->allocMeshes(numProxies); |
Brian Salomon | 12d2264 | 2019-01-29 14:38:50 -0500 | [diff] [blame] | 486 | sk_sp<const GrBuffer> vbuffer; |
Brian Salomon | 4b8178f | 2018-10-12 13:18:27 -0400 | [diff] [blame] | 487 | int vertexOffsetInBuffer = 0; |
Michael Ludwig | 93aeba0 | 2018-12-21 09:50:31 -0500 | [diff] [blame] | 488 | int numQuadVerticesLeft = numTotalQuads * vertexSpec.verticesPerQuad(); |
Brian Salomon | 4b8178f | 2018-10-12 13:18:27 -0400 | [diff] [blame] | 489 | int numAllocatedVertices = 0; |
| 490 | void* vdata = nullptr; |
| 491 | |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 492 | int m = 0; |
Brian Salomon | f723264 | 2018-09-19 08:58:08 -0400 | [diff] [blame] | 493 | for (const auto& op : ChainRange<TextureOp>(this)) { |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 494 | int q = 0; |
| 495 | for (unsigned p = 0; p < op.fProxyCnt; ++p) { |
| 496 | int quadCnt = op.fProxies[p].fQuadCnt; |
| 497 | auto* proxy = op.fProxies[p].fProxy; |
Michael Ludwig | 93aeba0 | 2018-12-21 09:50:31 -0500 | [diff] [blame] | 498 | int meshVertexCnt = quadCnt * vertexSpec.verticesPerQuad(); |
Brian Salomon | 4b8178f | 2018-10-12 13:18:27 -0400 | [diff] [blame] | 499 | if (numAllocatedVertices < meshVertexCnt) { |
| 500 | vdata = target->makeVertexSpaceAtLeast( |
| 501 | vertexSize, meshVertexCnt, numQuadVerticesLeft, &vbuffer, |
| 502 | &vertexOffsetInBuffer, &numAllocatedVertices); |
| 503 | SkASSERT(numAllocatedVertices <= numQuadVerticesLeft); |
| 504 | if (!vdata) { |
| 505 | SkDebugf("Could not allocate vertices\n"); |
| 506 | return; |
| 507 | } |
Brian Salomon | f723264 | 2018-09-19 08:58:08 -0400 | [diff] [blame] | 508 | } |
Brian Salomon | 4b8178f | 2018-10-12 13:18:27 -0400 | [diff] [blame] | 509 | SkASSERT(numAllocatedVertices >= meshVertexCnt); |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 510 | |
Michael Ludwig | c182b94 | 2018-11-16 10:27:51 -0500 | [diff] [blame] | 511 | op.tess(vdata, vertexSpec, proxy, q, quadCnt); |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 512 | |
Michael Ludwig | 93aeba0 | 2018-12-21 09:50:31 -0500 | [diff] [blame] | 513 | if (!GrQuadPerEdgeAA::ConfigureMeshIndices(target, &(meshes[m]), vertexSpec, |
| 514 | quadCnt)) { |
| 515 | SkDebugf("Could not allocate indices"); |
| 516 | return; |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 517 | } |
Brian Salomon | 4b8178f | 2018-10-12 13:18:27 -0400 | [diff] [blame] | 518 | meshes[m].setVertexData(vbuffer, vertexOffsetInBuffer); |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 519 | if (dynamicStateArrays) { |
| 520 | dynamicStateArrays->fPrimitiveProcessorTextures[m] = proxy; |
| 521 | } |
| 522 | ++m; |
Brian Salomon | 4b8178f | 2018-10-12 13:18:27 -0400 | [diff] [blame] | 523 | numAllocatedVertices -= meshVertexCnt; |
| 524 | numQuadVerticesLeft -= meshVertexCnt; |
| 525 | vertexOffsetInBuffer += meshVertexCnt; |
| 526 | vdata = reinterpret_cast<char*>(vdata) + vertexSize * meshVertexCnt; |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 527 | q += quadCnt; |
Brian Salomon | f723264 | 2018-09-19 08:58:08 -0400 | [diff] [blame] | 528 | } |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 529 | } |
Brian Salomon | 4b8178f | 2018-10-12 13:18:27 -0400 | [diff] [blame] | 530 | SkASSERT(!numQuadVerticesLeft); |
| 531 | SkASSERT(!numAllocatedVertices); |
Chris Dalton | 07cdcfc9 | 2019-02-26 11:13:22 -0700 | [diff] [blame] | 532 | target->recordDraw( |
| 533 | std::move(gp), meshes, numProxies, fixedDynamicState, dynamicStateArrays); |
| 534 | } |
| 535 | |
| 536 | void onExecute(GrOpFlushState* flushState, const SkRect& chainBounds) override { |
| 537 | auto pipelineFlags = (GrAAType::kMSAA == this->aaType()) |
Chris Dalton | baa1b35 | 2019-04-03 12:03:00 -0600 | [diff] [blame] | 538 | ? GrPipeline::InputFlags::kHWAntialias |
| 539 | : GrPipeline::InputFlags::kNone; |
Chris Dalton | 07cdcfc9 | 2019-02-26 11:13:22 -0700 | [diff] [blame] | 540 | flushState->executeDrawsAndUploadsForMeshDrawOp( |
| 541 | this, chainBounds, GrProcessorSet::MakeEmptySet(), pipelineFlags); |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 542 | } |
| 543 | |
Brian Salomon | f723264 | 2018-09-19 08:58:08 -0400 | [diff] [blame] | 544 | CombineResult onCombineIfPossible(GrOp* t, const GrCaps& caps) override { |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 545 | TRACE_EVENT0("skia", TRACE_FUNC); |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 546 | const auto* that = t->cast<TextureOp>(); |
Michael Ludwig | 2929f51 | 2019-04-19 13:05:56 -0400 | [diff] [blame] | 547 | if (fDomain != that->fDomain) { |
| 548 | // It is technically possible to combine operations across domain modes, but performance |
| 549 | // testing suggests it's better to make more draw calls where some take advantage of |
| 550 | // the more optimal shader path without coordinate clamping. |
| 551 | return CombineResult::kCannotCombine; |
| 552 | } |
Brian Osman | 3ebd354 | 2018-07-30 14:36:53 -0400 | [diff] [blame] | 553 | if (!GrColorSpaceXform::Equals(fTextureColorSpaceXform.get(), |
| 554 | that->fTextureColorSpaceXform.get())) { |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 555 | return CombineResult::kCannotCombine; |
Brian Osman | 3ebd354 | 2018-07-30 14:36:53 -0400 | [diff] [blame] | 556 | } |
Brian Salomon | ae7d770 | 2018-10-14 15:05:45 -0400 | [diff] [blame] | 557 | bool upgradeToCoverageAAOnMerge = false; |
Brian Salomon | 485b8c6 | 2018-01-12 15:11:06 -0500 | [diff] [blame] | 558 | if (this->aaType() != that->aaType()) { |
Brian Salomon | ae7d770 | 2018-10-14 15:05:45 -0400 | [diff] [blame] | 559 | if (!((this->aaType() == GrAAType::kCoverage && that->aaType() == GrAAType::kNone) || |
| 560 | (that->aaType() == GrAAType::kCoverage && this->aaType() == GrAAType::kNone))) { |
| 561 | return CombineResult::kCannotCombine; |
| 562 | } |
| 563 | upgradeToCoverageAAOnMerge = true; |
Brian Salomon | b5ef1f9 | 2018-01-11 11:46:21 -0500 | [diff] [blame] | 564 | } |
Brian Salomon | f723264 | 2018-09-19 08:58:08 -0400 | [diff] [blame] | 565 | if (fFilter != that->fFilter) { |
| 566 | return CombineResult::kCannotCombine; |
| 567 | } |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 568 | auto thisProxy = fProxies[0].fProxy; |
| 569 | auto thatProxy = that->fProxies[0].fProxy; |
| 570 | if (fProxyCnt > 1 || that->fProxyCnt > 1 || |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 571 | thisProxy->uniqueID() != thatProxy->uniqueID()) { |
| 572 | // We can't merge across different proxies. Check if 'this' can be chained with 'that'. |
Greg Daniel | 45723ac | 2018-11-30 10:12:43 -0500 | [diff] [blame] | 573 | if (GrTextureProxy::ProxiesAreCompatibleAsDynamicState(thisProxy, thatProxy) && |
Brian Salomon | f723264 | 2018-09-19 08:58:08 -0400 | [diff] [blame] | 574 | caps.dynamicStateArrayGeometryProcessorTextureSupport()) { |
| 575 | return CombineResult::kMayChain; |
| 576 | } |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 577 | return CombineResult::kCannotCombine; |
Brian Salomon | 336ce7b | 2017-09-08 08:23:58 -0400 | [diff] [blame] | 578 | } |
Michael Ludwig | 009b92e | 2019-02-15 16:03:53 -0500 | [diff] [blame] | 579 | |
Brian Salomon | b80ffee | 2018-05-23 16:39:39 -0400 | [diff] [blame] | 580 | fDomain |= that->fDomain; |
Brian Salomon | 1d83542 | 2019-03-13 16:11:44 -0400 | [diff] [blame] | 581 | fColorType = SkTMax(fColorType, that->fColorType); |
Brian Salomon | ae7d770 | 2018-10-14 15:05:45 -0400 | [diff] [blame] | 582 | if (upgradeToCoverageAAOnMerge) { |
| 583 | fAAType = static_cast<unsigned>(GrAAType::kCoverage); |
| 584 | } |
Michael Ludwig | 009b92e | 2019-02-15 16:03:53 -0500 | [diff] [blame] | 585 | |
| 586 | // Concatenate quad lists together, updating the fSrcQuadIndex in the appended quads |
| 587 | // to account for the new starting index in fSrcQuads |
| 588 | int srcQuadOffset = fSrcQuads.count(); |
| 589 | int oldQuadCount = fQuads.count(); |
| 590 | |
| 591 | fSrcQuads.concat(that->fSrcQuads); |
| 592 | fQuads.concat(that->fQuads); |
| 593 | fProxies[0].fQuadCnt += that->fQuads.count(); |
| 594 | |
| 595 | if (that->fSrcQuads.count() > 0) { |
| 596 | // Some of the concatenated quads pointed to fSrcQuads, so adjust the indices for the |
| 597 | // newly appended quads |
| 598 | for (int i = oldQuadCount; i < fQuads.count(); ++i) { |
| 599 | if (fQuads.metadata(i).fSrcQuadIndex >= 0) { |
| 600 | fQuads.metadata(i).fSrcQuadIndex += srcQuadOffset; |
| 601 | } |
| 602 | } |
| 603 | } |
| 604 | |
| 605 | // Confirm all tracked state makes sense when in debug builds |
| 606 | #ifdef SK_DEBUG |
| 607 | SkASSERT(fSrcQuads.count() <= fQuads.count()); |
| 608 | for (int i = 0; i < fQuads.count(); ++i) { |
| 609 | int srcIndex = fQuads.metadata(i).fSrcQuadIndex; |
| 610 | if (srcIndex >= 0) { |
| 611 | // Make sure it points to a valid index, in the right region of the list |
| 612 | SkASSERT(srcIndex < fSrcQuads.count()); |
| 613 | SkASSERT((i < oldQuadCount && srcIndex < srcQuadOffset) || |
| 614 | (i >= oldQuadCount && srcIndex >= srcQuadOffset)); |
| 615 | } |
| 616 | } |
| 617 | #endif |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 618 | return CombineResult::kMerged; |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 619 | } |
| 620 | |
Brian Salomon | 485b8c6 | 2018-01-12 15:11:06 -0500 | [diff] [blame] | 621 | GrAAType aaType() const { return static_cast<GrAAType>(fAAType); } |
Brian Salomon | 0087c83 | 2018-10-15 14:48:20 -0400 | [diff] [blame] | 622 | GrSamplerState::Filter filter() const { return static_cast<GrSamplerState::Filter>(fFilter); } |
Brian Salomon | b5ef1f9 | 2018-01-11 11:46:21 -0500 | [diff] [blame] | 623 | |
Michael Ludwig | c96fc37 | 2019-01-08 15:46:15 -0500 | [diff] [blame] | 624 | struct ColorDomainAndAA { |
| 625 | // Special constructor to convert enums into the packed bits, which should not delete |
| 626 | // the implicit move constructor (but it does require us to declare an empty ctor for |
| 627 | // use with the GrTQuadList). |
Michael Ludwig | 009b92e | 2019-02-15 16:03:53 -0500 | [diff] [blame] | 628 | ColorDomainAndAA(const SkPMColor4f& color, const SkRect& srcRect, int srcQuadIndex, |
Michael Ludwig | c96fc37 | 2019-01-08 15:46:15 -0500 | [diff] [blame] | 629 | Domain hasDomain, GrQuadAAFlags aaFlags) |
| 630 | : fColor(color) |
| 631 | , fSrcRect(srcRect) |
Michael Ludwig | 009b92e | 2019-02-15 16:03:53 -0500 | [diff] [blame] | 632 | , fSrcQuadIndex(srcQuadIndex) |
Michael Ludwig | c96fc37 | 2019-01-08 15:46:15 -0500 | [diff] [blame] | 633 | , fHasDomain(static_cast<unsigned>(hasDomain)) |
Brian Salomon | 2213ee9 | 2018-10-02 10:44:21 -0400 | [diff] [blame] | 634 | , fAAFlags(static_cast<unsigned>(aaFlags)) { |
Michael Ludwig | c96fc37 | 2019-01-08 15:46:15 -0500 | [diff] [blame] | 635 | SkASSERT(fHasDomain == static_cast<unsigned>(hasDomain)); |
Brian Salomon | 2213ee9 | 2018-10-02 10:44:21 -0400 | [diff] [blame] | 636 | SkASSERT(fAAFlags == static_cast<unsigned>(aaFlags)); |
| 637 | } |
Michael Ludwig | c96fc37 | 2019-01-08 15:46:15 -0500 | [diff] [blame] | 638 | ColorDomainAndAA() = default; |
Michael Ludwig | 23d8943e | 2019-01-04 14:51:40 +0000 | [diff] [blame] | 639 | |
Michael Ludwig | 23d8943e | 2019-01-04 14:51:40 +0000 | [diff] [blame] | 640 | SkPMColor4f fColor; |
Michael Ludwig | 009b92e | 2019-02-15 16:03:53 -0500 | [diff] [blame] | 641 | // Even if fSrcQuadIndex provides source coords, use fSrcRect for domain constraint |
Michael Ludwig | c96fc37 | 2019-01-08 15:46:15 -0500 | [diff] [blame] | 642 | SkRect fSrcRect; |
Michael Ludwig | 009b92e | 2019-02-15 16:03:53 -0500 | [diff] [blame] | 643 | // If >= 0, use to access fSrcQuads instead of fSrcRect for the source coordinates |
| 644 | int fSrcQuadIndex; |
Michael Ludwig | 23d8943e | 2019-01-04 14:51:40 +0000 | [diff] [blame] | 645 | unsigned fHasDomain : 1; |
| 646 | unsigned fAAFlags : 4; |
Michael Ludwig | c96fc37 | 2019-01-08 15:46:15 -0500 | [diff] [blame] | 647 | |
| 648 | Domain domain() const { return Domain(fHasDomain); } |
| 649 | GrQuadAAFlags aaFlags() const { return static_cast<GrQuadAAFlags>(fAAFlags); } |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 650 | }; |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 651 | struct Proxy { |
| 652 | GrTextureProxy* fProxy; |
| 653 | int fQuadCnt; |
| 654 | }; |
Michael Ludwig | c96fc37 | 2019-01-08 15:46:15 -0500 | [diff] [blame] | 655 | GrTQuadList<ColorDomainAndAA> fQuads; |
Michael Ludwig | 009b92e | 2019-02-15 16:03:53 -0500 | [diff] [blame] | 656 | // The majority of texture ops will not track a complete src quad so this is indexed separately |
| 657 | // and may be of different size to fQuads. |
| 658 | GrQuadList fSrcQuads; |
Brian Osman | 3ebd354 | 2018-07-30 14:36:53 -0400 | [diff] [blame] | 659 | sk_sp<GrColorSpaceXform> fTextureColorSpaceXform; |
Brian Salomon | 0087c83 | 2018-10-15 14:48:20 -0400 | [diff] [blame] | 660 | unsigned fFilter : 2; |
Brian Salomon | 485b8c6 | 2018-01-12 15:11:06 -0500 | [diff] [blame] | 661 | unsigned fAAType : 2; |
Brian Salomon | b80ffee | 2018-05-23 16:39:39 -0400 | [diff] [blame] | 662 | unsigned fDomain : 1; |
Brian Salomon | 1d83542 | 2019-03-13 16:11:44 -0400 | [diff] [blame] | 663 | unsigned fColorType : 2; |
| 664 | GR_STATIC_ASSERT(GrQuadPerEdgeAA::kColorTypeCount <= 4); |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 665 | // 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] | 666 | unsigned fFinalized : 1; |
Robert Phillips | 5f78adf | 2019-04-22 12:41:39 -0400 | [diff] [blame] | 667 | unsigned fProxyCnt : 32 - 8; |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 668 | Proxy fProxies[1]; |
Brian Salomon | 336ce7b | 2017-09-08 08:23:58 -0400 | [diff] [blame] | 669 | |
Michael Ludwig | f995c05 | 2018-11-26 15:24:29 -0500 | [diff] [blame] | 670 | static_assert(kGrQuadTypeCount <= 4, "GrQuadType does not fit in 2 bits"); |
| 671 | |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 672 | typedef GrMeshDrawOp INHERITED; |
| 673 | }; |
| 674 | |
| 675 | } // anonymous namespace |
| 676 | |
| 677 | namespace GrTextureOp { |
| 678 | |
Robert Phillips | b97da53 | 2019-02-12 15:24:12 -0500 | [diff] [blame] | 679 | std::unique_ptr<GrDrawOp> Make(GrRecordingContext* context, |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 680 | sk_sp<GrTextureProxy> proxy, |
| 681 | GrSamplerState::Filter filter, |
Brian Osman | 3d139a4 | 2018-11-19 10:42:10 -0500 | [diff] [blame] | 682 | const SkPMColor4f& color, |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 683 | const SkRect& srcRect, |
| 684 | const SkRect& dstRect, |
| 685 | GrAAType aaType, |
Brian Salomon | 2213ee9 | 2018-10-02 10:44:21 -0400 | [diff] [blame] | 686 | GrQuadAAFlags aaFlags, |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 687 | SkCanvas::SrcRectConstraint constraint, |
| 688 | const SkMatrix& viewMatrix, |
Brian Osman | 3d139a4 | 2018-11-19 10:42:10 -0500 | [diff] [blame] | 689 | sk_sp<GrColorSpaceXform> textureColorSpaceXform) { |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 690 | return TextureOp::Make(context, std::move(proxy), filter, color, srcRect, dstRect, aaType, |
Brian Osman | 3d139a4 | 2018-11-19 10:42:10 -0500 | [diff] [blame] | 691 | aaFlags, constraint, viewMatrix, std::move(textureColorSpaceXform)); |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 692 | } |
| 693 | |
Michael Ludwig | 009b92e | 2019-02-15 16:03:53 -0500 | [diff] [blame] | 694 | std::unique_ptr<GrDrawOp> MakeQuad(GrRecordingContext* context, |
| 695 | sk_sp<GrTextureProxy> proxy, |
| 696 | GrSamplerState::Filter filter, |
| 697 | const SkPMColor4f& color, |
| 698 | const SkPoint srcQuad[4], |
| 699 | const SkPoint dstQuad[4], |
| 700 | GrAAType aaType, |
| 701 | GrQuadAAFlags aaFlags, |
| 702 | const SkRect* domain, |
| 703 | const SkMatrix& viewMatrix, |
| 704 | sk_sp<GrColorSpaceXform> textureXform) { |
| 705 | return TextureOp::Make(context, std::move(proxy), filter, color, srcQuad, dstQuad, aaType, |
| 706 | aaFlags, domain, viewMatrix, std::move(textureXform)); |
| 707 | } |
| 708 | |
| 709 | std::unique_ptr<GrDrawOp> MakeSet(GrRecordingContext* context, |
| 710 | const GrRenderTargetContext::TextureSetEntry set[], |
| 711 | int cnt, |
| 712 | GrSamplerState::Filter filter, |
| 713 | GrAAType aaType, |
Michael Ludwig | 31ba718 | 2019-04-03 10:38:06 -0400 | [diff] [blame] | 714 | SkCanvas::SrcRectConstraint constraint, |
Michael Ludwig | 009b92e | 2019-02-15 16:03:53 -0500 | [diff] [blame] | 715 | const SkMatrix& viewMatrix, |
| 716 | sk_sp<GrColorSpaceXform> textureColorSpaceXform) { |
Michael Ludwig | 31ba718 | 2019-04-03 10:38:06 -0400 | [diff] [blame] | 717 | return TextureOp::Make(context, set, cnt, filter, aaType, constraint, viewMatrix, |
Brian Osman | 3d139a4 | 2018-11-19 10:42:10 -0500 | [diff] [blame] | 718 | std::move(textureColorSpaceXform)); |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 719 | } |
| 720 | |
Michael Ludwig | a3c45c7 | 2019-01-17 17:26:48 -0500 | [diff] [blame] | 721 | bool GetFilterHasEffect(const SkMatrix& viewMatrix, const SkRect& srcRect, const SkRect& dstRect) { |
| 722 | // Hypothetically we could disable bilerp filtering when flipping or rotating 90 degrees, but |
| 723 | // that makes the math harder and we don't want to increase the overhead of the checks |
| 724 | if (!viewMatrix.isScaleTranslate() || |
| 725 | viewMatrix.getScaleX() < 0.0f || viewMatrix.getScaleY() < 0.0f) { |
| 726 | return true; |
| 727 | } |
| 728 | |
| 729 | // Given the matrix conditions ensured above, this computes the device space coordinates for |
| 730 | // the top left corner of dstRect and its size. |
| 731 | SkScalar dw = viewMatrix.getScaleX() * dstRect.width(); |
| 732 | SkScalar dh = viewMatrix.getScaleY() * dstRect.height(); |
| 733 | SkScalar dl = viewMatrix.getScaleX() * dstRect.fLeft + viewMatrix.getTranslateX(); |
| 734 | SkScalar dt = viewMatrix.getScaleY() * dstRect.fTop + viewMatrix.getTranslateY(); |
| 735 | |
| 736 | // Disable filtering when there is no scaling of the src rect and the src rect and dst rect |
| 737 | // align fractionally. If we allow inverted src rects this logic needs to consider that. |
| 738 | SkASSERT(srcRect.isSorted()); |
| 739 | return dw != srcRect.width() || dh != srcRect.height() || |
| 740 | SkScalarFraction(dl) != SkScalarFraction(srcRect.fLeft) || |
| 741 | SkScalarFraction(dt) != SkScalarFraction(srcRect.fTop); |
| 742 | } |
| 743 | |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 744 | } // namespace GrTextureOp |
| 745 | |
| 746 | #if GR_TEST_UTILS |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 747 | #include "GrProxyProvider.h" |
Robert Phillips | b97da53 | 2019-02-12 15:24:12 -0500 | [diff] [blame] | 748 | #include "GrRecordingContext.h" |
| 749 | #include "GrRecordingContextPriv.h" |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 750 | |
| 751 | GR_DRAW_OP_TEST_DEFINE(TextureOp) { |
| 752 | GrSurfaceDesc desc; |
| 753 | desc.fConfig = kRGBA_8888_GrPixelConfig; |
| 754 | desc.fHeight = random->nextULessThan(90) + 10; |
| 755 | desc.fWidth = random->nextULessThan(90) + 10; |
Brian Salomon | 2a4f983 | 2018-03-03 22:43:43 -0500 | [diff] [blame] | 756 | auto origin = random->nextBool() ? kTopLeft_GrSurfaceOrigin : kBottomLeft_GrSurfaceOrigin; |
Greg Daniel | 09c9400 | 2018-06-08 22:11:51 +0000 | [diff] [blame] | 757 | GrMipMapped mipMapped = random->nextBool() ? GrMipMapped::kYes : GrMipMapped::kNo; |
| 758 | SkBackingFit fit = SkBackingFit::kExact; |
| 759 | if (mipMapped == GrMipMapped::kNo) { |
| 760 | fit = random->nextBool() ? SkBackingFit::kApprox : SkBackingFit::kExact; |
| 761 | } |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 762 | |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 763 | const GrBackendFormat format = |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 764 | context->priv().caps()->getBackendFormatFromColorType(kRGBA_8888_SkColorType); |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 765 | |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 766 | GrProxyProvider* proxyProvider = context->priv().proxyProvider(); |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 767 | sk_sp<GrTextureProxy> proxy = proxyProvider->createProxy(format, desc, origin, mipMapped, fit, |
Greg Daniel | 09c9400 | 2018-06-08 22:11:51 +0000 | [diff] [blame] | 768 | SkBudgeted::kNo, |
| 769 | GrInternalSurfaceFlags::kNone); |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 770 | |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 771 | SkRect rect = GrTest::TestRect(random); |
| 772 | SkRect srcRect; |
| 773 | srcRect.fLeft = random->nextRangeScalar(0.f, proxy->width() / 2.f); |
| 774 | srcRect.fRight = random->nextRangeScalar(0.f, proxy->width()) + proxy->width() / 2.f; |
| 775 | srcRect.fTop = random->nextRangeScalar(0.f, proxy->height() / 2.f); |
| 776 | srcRect.fBottom = random->nextRangeScalar(0.f, proxy->height()) + proxy->height() / 2.f; |
| 777 | SkMatrix viewMatrix = GrTest::TestMatrixPreservesRightAngles(random); |
Brian Osman | 3d139a4 | 2018-11-19 10:42:10 -0500 | [diff] [blame] | 778 | SkPMColor4f color = SkPMColor4f::FromBytes_RGBA(SkColorToPremulGrColor(random->nextU())); |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 779 | GrSamplerState::Filter filter = (GrSamplerState::Filter)random->nextULessThan( |
| 780 | static_cast<uint32_t>(GrSamplerState::Filter::kMipMap) + 1); |
Greg Daniel | 09c9400 | 2018-06-08 22:11:51 +0000 | [diff] [blame] | 781 | while (mipMapped == GrMipMapped::kNo && filter == GrSamplerState::Filter::kMipMap) { |
| 782 | filter = (GrSamplerState::Filter)random->nextULessThan( |
| 783 | static_cast<uint32_t>(GrSamplerState::Filter::kMipMap) + 1); |
| 784 | } |
Brian Osman | 3ebd354 | 2018-07-30 14:36:53 -0400 | [diff] [blame] | 785 | auto texXform = GrTest::TestColorXform(random); |
Brian Salomon | 485b8c6 | 2018-01-12 15:11:06 -0500 | [diff] [blame] | 786 | GrAAType aaType = GrAAType::kNone; |
| 787 | if (random->nextBool()) { |
| 788 | aaType = (fsaaType == GrFSAAType::kUnifiedMSAA) ? GrAAType::kMSAA : GrAAType::kCoverage; |
| 789 | } |
Brian Salomon | 2213ee9 | 2018-10-02 10:44:21 -0400 | [diff] [blame] | 790 | GrQuadAAFlags aaFlags = GrQuadAAFlags::kNone; |
| 791 | aaFlags |= random->nextBool() ? GrQuadAAFlags::kLeft : GrQuadAAFlags::kNone; |
| 792 | aaFlags |= random->nextBool() ? GrQuadAAFlags::kTop : GrQuadAAFlags::kNone; |
| 793 | aaFlags |= random->nextBool() ? GrQuadAAFlags::kRight : GrQuadAAFlags::kNone; |
| 794 | aaFlags |= random->nextBool() ? GrQuadAAFlags::kBottom : GrQuadAAFlags::kNone; |
Brian Salomon | b80ffee | 2018-05-23 16:39:39 -0400 | [diff] [blame] | 795 | auto constraint = random->nextBool() ? SkCanvas::kStrict_SrcRectConstraint |
| 796 | : SkCanvas::kFast_SrcRectConstraint; |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 797 | return GrTextureOp::Make(context, std::move(proxy), filter, color, srcRect, rect, aaType, |
Brian Osman | 3d139a4 | 2018-11-19 10:42:10 -0500 | [diff] [blame] | 798 | aaFlags, constraint, viewMatrix, std::move(texXform)); |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 799 | } |
| 800 | |
| 801 | #endif |