blob: 4ebe9f6379ad28f17496abbcd9c8ee32043bc15c [file] [log] [blame]
Brian Salomon34169692017-08-28 15:32:01 -04001/*
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 Salomond7065e72018-10-12 11:42:02 -04009#include <new>
Brian Salomon34169692017-08-28 15:32:01 -040010#include "GrAppliedClip.h"
Brian Salomon336ce7b2017-09-08 08:23:58 -040011#include "GrCaps.h"
Robert Phillips7c525e62018-06-12 10:11:12 -040012#include "GrContext.h"
13#include "GrContextPriv.h"
Brian Salomon34169692017-08-28 15:32:01 -040014#include "GrDrawOpTest.h"
15#include "GrGeometryProcessor.h"
Greg Daniel7a82edf2018-12-04 10:54:34 -050016#include "GrGpu.h"
Robert Phillips7c525e62018-06-12 10:11:12 -040017#include "GrMemoryPool.h"
Brian Salomon34169692017-08-28 15:32:01 -040018#include "GrMeshDrawOp.h"
19#include "GrOpFlushState.h"
20#include "GrQuad.h"
Michael Ludwig460eb5e2018-10-29 11:09:29 -040021#include "GrQuadPerEdgeAA.h"
Brian Salomon34169692017-08-28 15:32:01 -040022#include "GrResourceProvider.h"
Greg Daniel7a82edf2018-12-04 10:54:34 -050023#include "GrResourceProviderPriv.h"
Brian Salomon34169692017-08-28 15:32:01 -040024#include "GrShaderCaps.h"
25#include "GrTexture.h"
Brian Salomon336ce7b2017-09-08 08:23:58 -040026#include "GrTexturePriv.h"
Brian Salomon34169692017-08-28 15:32:01 -040027#include "GrTextureProxy.h"
28#include "SkGr.h"
Brian Salomon336ce7b2017-09-08 08:23:58 -040029#include "SkMathPriv.h"
Brian Salomona33b67c2018-05-17 10:42:14 -040030#include "SkMatrixPriv.h"
Brian Salomonb5ef1f92018-01-11 11:46:21 -050031#include "SkPoint.h"
32#include "SkPoint3.h"
Brian Salomond7065e72018-10-12 11:42:02 -040033#include "SkRectPriv.h"
Hal Canaryc640d0d2018-06-13 09:59:02 -040034#include "SkTo.h"
Brian Salomon34169692017-08-28 15:32:01 -040035#include "glsl/GrGLSLVarying.h"
36
37namespace {
38
Michael Ludwig460eb5e2018-10-29 11:09:29 -040039using Domain = GrQuadPerEdgeAA::Domain;
Michael Ludwigc182b942018-11-16 10:27:51 -050040using VertexSpec = GrQuadPerEdgeAA::VertexSpec;
Brian Osman3d139a42018-11-19 10:42:10 -050041using ColorType = GrQuadPerEdgeAA::ColorType;
Brian Salomonb80ffee2018-05-23 16:39:39 -040042
Brian Salomon246bc3d2018-12-06 15:33:02 -050043// if normalizing the domain then pass 1/width, 1/height, 1 for iw, ih, h. Otherwise pass
44// 1, 1, and height.
45static 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 Ludwig460eb5e2018-10-29 11:09:29 -040048 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 Salomon246bc3d2018-12-06 15:33:02 -050066 const Sk4f kAdd = {0.f, h, 0.f, h};
Michael Ludwig460eb5e2018-10-29 11:09:29 -040067 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 Salomon246bc3d2018-12-06 15:33:02 -050075// If normalizing the src quad then pass 1/width, 1/height, 1 for iw, ih, h. Otherwise pass
76// 1, 1, and height.
77static GrPerspQuad compute_src_quad(GrSurfaceOrigin origin, const SkRect& srcRect, float iw,
78 float ih, float h) {
Michael Ludwig460eb5e2018-10-29 11:09:29 -040079 // 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 Salomon246bc3d2018-12-06 15:33:02 -050087 texRect.fTop = h - texRect.fTop;
88 texRect.fBottom = h - texRect.fBottom;
Michael Ludwig460eb5e2018-10-29 11:09:29 -040089 }
90 return GrPerspQuad(texRect, SkMatrix::I());
91}
92
Brian Salomon34169692017-08-28 15:32:01 -040093/**
94 * Op that implements GrTextureOp::Make. It draws textured quads. Each quad can modulate against a
95 * the texture by color. The blend with the destination is always src-over. The edges are non-AA.
96 */
97class TextureOp final : public GrMeshDrawOp {
98public:
Robert Phillips7c525e62018-06-12 10:11:12 -040099 static std::unique_ptr<GrDrawOp> Make(GrContext* context,
100 sk_sp<GrTextureProxy> proxy,
101 GrSamplerState::Filter filter,
Brian Osman3d139a42018-11-19 10:42:10 -0500102 const SkPMColor4f& color,
Robert Phillips7c525e62018-06-12 10:11:12 -0400103 const SkRect& srcRect,
104 const SkRect& dstRect,
105 GrAAType aaType,
Brian Salomon2213ee92018-10-02 10:44:21 -0400106 GrQuadAAFlags aaFlags,
Robert Phillips7c525e62018-06-12 10:11:12 -0400107 SkCanvas::SrcRectConstraint constraint,
Brian Osman2b23c4b2018-06-01 12:25:08 -0400108 const SkMatrix& viewMatrix,
Brian Osman3d139a42018-11-19 10:42:10 -0500109 sk_sp<GrColorSpaceXform> textureColorSpaceXform) {
Robert Phillips9da87e02019-02-04 13:26:26 -0500110 GrOpMemoryPool* pool = context->priv().opMemoryPool();
Robert Phillipsc994a932018-06-19 13:09:54 -0400111
Brian Salomon2213ee92018-10-02 10:44:21 -0400112 return pool->allocate<TextureOp>(
113 std::move(proxy), filter, color, srcRect, dstRect, aaType, aaFlags, constraint,
Brian Osman3d139a42018-11-19 10:42:10 -0500114 viewMatrix, std::move(textureColorSpaceXform));
Brian Salomon34169692017-08-28 15:32:01 -0400115 }
Brian Salomond7065e72018-10-12 11:42:02 -0400116 static std::unique_ptr<GrDrawOp> Make(GrContext* context,
117 const GrRenderTargetContext::TextureSetEntry set[],
Brian Salomond003d222018-11-26 13:25:05 -0500118 int cnt, GrSamplerState::Filter filter, GrAAType aaType,
119 const SkMatrix& viewMatrix,
Brian Osman3d139a42018-11-19 10:42:10 -0500120 sk_sp<GrColorSpaceXform> textureColorSpaceXform) {
Brian Salomond7065e72018-10-12 11:42:02 -0400121 size_t size = sizeof(TextureOp) + sizeof(Proxy) * (cnt - 1);
Robert Phillips9da87e02019-02-04 13:26:26 -0500122 GrOpMemoryPool* pool = context->priv().opMemoryPool();
Brian Salomond7065e72018-10-12 11:42:02 -0400123 void* mem = pool->allocate(size);
Brian Salomond003d222018-11-26 13:25:05 -0500124 return std::unique_ptr<GrDrawOp>(new (mem) TextureOp(set, cnt, filter, aaType, viewMatrix,
125 std::move(textureColorSpaceXform)));
Brian Salomond7065e72018-10-12 11:42:02 -0400126 }
Brian Salomon34169692017-08-28 15:32:01 -0400127
Brian Salomon336ce7b2017-09-08 08:23:58 -0400128 ~TextureOp() override {
Brian Salomond7065e72018-10-12 11:42:02 -0400129 for (unsigned p = 0; p < fProxyCnt; ++p) {
130 if (fFinalized) {
131 fProxies[p].fProxy->completedRead();
132 } else {
133 fProxies[p].fProxy->unref();
134 }
Brian Salomon336ce7b2017-09-08 08:23:58 -0400135 }
136 }
Brian Salomon34169692017-08-28 15:32:01 -0400137
138 const char* name() const override { return "TextureOp"; }
139
Brian Salomon7d94bb52018-10-12 14:37:19 -0400140 void visitProxies(const VisitProxyFunc& func, VisitorType visitor) const override {
141 if (visitor == VisitorType::kAllocatorGather && fCanSkipAllocatorGather) {
142 return;
143 }
Brian Salomond7065e72018-10-12 11:42:02 -0400144 for (unsigned p = 0; p < fProxyCnt; ++p) {
145 func(fProxies[p].fProxy);
146 }
147 }
Robert Phillipsb493eeb2017-09-13 13:10:52 -0400148
Brian Osman9a390ac2018-11-12 09:47:48 -0500149#ifdef SK_DEBUG
Brian Salomon34169692017-08-28 15:32:01 -0400150 SkString dumpInfo() const override {
151 SkString str;
Brian Salomond7065e72018-10-12 11:42:02 -0400152 str.appendf("# draws: %d\n", fQuads.count());
153 int q = 0;
154 for (unsigned p = 0; p < fProxyCnt; ++p) {
155 str.appendf("Proxy ID: %d, Filter: %d\n", fProxies[p].fProxy->uniqueID().asUInt(),
156 static_cast<int>(fFilter));
157 for (int i = 0; i < fProxies[p].fQuadCnt; ++i, ++q) {
Michael Ludwigc96fc372019-01-08 15:46:15 -0500158 GrPerspQuad quad = fQuads[q];
159 const ColorDomainAndAA& info = fQuads.metadata(i);
Brian Salomond7065e72018-10-12 11:42:02 -0400160 str.appendf(
161 "%d: Color: 0x%08x, TexRect [L: %.2f, T: %.2f, R: %.2f, B: %.2f] "
162 "Quad [(%.2f, %.2f), (%.2f, %.2f), (%.2f, %.2f), (%.2f, %.2f)]\n",
Michael Ludwigc96fc372019-01-08 15:46:15 -0500163 i, info.fColor.toBytes_RGBA(), info.fSrcRect.fLeft, info.fSrcRect.fTop,
164 info.fSrcRect.fRight, info.fSrcRect.fBottom, quad.point(0).fX,
165 quad.point(0).fY, quad.point(1).fX, quad.point(1).fY,
166 quad.point(2).fX, quad.point(2).fY, quad.point(3).fX,
167 quad.point(3).fY);
Brian Salomond7065e72018-10-12 11:42:02 -0400168 }
Brian Salomon34169692017-08-28 15:32:01 -0400169 }
170 str += INHERITED::dumpInfo();
171 return str;
172 }
Brian Osman9a390ac2018-11-12 09:47:48 -0500173#endif
Brian Salomon34169692017-08-28 15:32:01 -0400174
Chris Dalton4b62aed2019-01-15 11:53:00 -0700175 GrProcessorSet::Analysis finalize(const GrCaps& caps, const GrAppliedClip* clip) override {
Brian Salomon34169692017-08-28 15:32:01 -0400176 SkASSERT(!fFinalized);
177 fFinalized = true;
Brian Salomond7065e72018-10-12 11:42:02 -0400178 for (unsigned p = 0; p < fProxyCnt; ++p) {
179 fProxies[p].fProxy->addPendingRead();
180 fProxies[p].fProxy->unref();
181 }
Chris Dalton4b62aed2019-01-15 11:53:00 -0700182 return GrProcessorSet::EmptySetAnalysis();
Brian Salomon34169692017-08-28 15:32:01 -0400183 }
184
Brian Salomon485b8c62018-01-12 15:11:06 -0500185 FixedFunctionFlags fixedFunctionFlags() const override {
186 return this->aaType() == GrAAType::kMSAA ? FixedFunctionFlags::kUsesHWAA
187 : FixedFunctionFlags::kNone;
188 }
Brian Salomon34169692017-08-28 15:32:01 -0400189
190 DEFINE_OP_CLASS_ID
191
192private:
Robert Phillips7c525e62018-06-12 10:11:12 -0400193 friend class ::GrOpMemoryPool;
Brian Salomon762d5e72017-12-01 10:25:08 -0500194
Brian Osman3d139a42018-11-19 10:42:10 -0500195 TextureOp(sk_sp<GrTextureProxy> proxy, GrSamplerState::Filter filter, const SkPMColor4f& color,
Brian Salomon2213ee92018-10-02 10:44:21 -0400196 const SkRect& srcRect, const SkRect& dstRect, GrAAType aaType, GrQuadAAFlags aaFlags,
Brian Salomonb80ffee2018-05-23 16:39:39 -0400197 SkCanvas::SrcRectConstraint constraint, const SkMatrix& viewMatrix,
Brian Osman3d139a42018-11-19 10:42:10 -0500198 sk_sp<GrColorSpaceXform> textureColorSpaceXform)
Brian Salomon34169692017-08-28 15:32:01 -0400199 : INHERITED(ClassID())
Brian Osman3ebd3542018-07-30 14:36:53 -0400200 , fTextureColorSpaceXform(std::move(textureColorSpaceXform))
Brian Salomon0087c832018-10-15 14:48:20 -0400201 , fFilter(static_cast<unsigned>(filter))
Brian Osman2b23c4b2018-06-01 12:25:08 -0400202 , fFinalized(0) {
Michael Ludwig6bee7762018-10-19 09:50:36 -0400203 GrQuadType quadType = GrQuadTypeForTransformedRect(viewMatrix);
Brian Salomon594b64c2018-05-29 12:47:57 -0400204 auto quad = GrPerspQuad(dstRect, viewMatrix);
Michael Ludwig6bee7762018-10-19 09:50:36 -0400205
206 // Clean up disparities between the overall aa type and edge configuration and apply
207 // optimizations based on the rect and matrix when appropriate
208 GrResolveAATypeForQuad(aaType, aaFlags, quad, quadType, &aaType, &aaFlags);
209 fAAType = static_cast<unsigned>(aaType);
210
Brian Salomonf1709042018-10-03 11:57:00 -0400211 // We expect our caller to have already caught this optimization.
Brian Salomond7065e72018-10-12 11:42:02 -0400212 SkASSERT(!srcRect.contains(proxy->getWorstCaseBoundsRect()) ||
Brian Salomonf1709042018-10-03 11:57:00 -0400213 constraint == SkCanvas::kFast_SrcRectConstraint);
Michael Ludwigc182b942018-11-16 10:27:51 -0500214 if (quadType == GrQuadType::kRect) {
Michael Ludwig6bee7762018-10-19 09:50:36 -0400215 // Disable filtering if possible (note AA optimizations for rects are automatically
216 // handled above in GrResolveAATypeForQuad).
Brian Salomon0087c832018-10-15 14:48:20 -0400217 if (this->filter() != GrSamplerState::Filter::kNearest &&
Michael Ludwiga3c45c72019-01-17 17:26:48 -0500218 !GrTextureOp::GetFilterHasEffect(viewMatrix, srcRect, dstRect)) {
Brian Salomon0087c832018-10-15 14:48:20 -0400219 fFilter = static_cast<unsigned>(GrSamplerState::Filter::kNearest);
Brian Salomon594b64c2018-05-29 12:47:57 -0400220 }
221 }
Brian Salomonf09abc52018-10-03 15:59:04 -0400222 // We may have had a strict constraint with nearest filter solely due to possible AA bloat.
223 // If we don't have (or determined we don't need) coverage AA then we can skip using a
224 // domain.
225 if (constraint == SkCanvas::kStrict_SrcRectConstraint &&
Brian Salomon0087c832018-10-15 14:48:20 -0400226 this->filter() == GrSamplerState::Filter::kNearest &&
Michael Ludwig6bee7762018-10-19 09:50:36 -0400227 aaType != GrAAType::kCoverage) {
Brian Salomonf09abc52018-10-03 15:59:04 -0400228 constraint = SkCanvas::kFast_SrcRectConstraint;
229 }
Michael Ludwigc96fc372019-01-08 15:46:15 -0500230
231 Domain domain = constraint == SkCanvas::kStrict_SrcRectConstraint ? Domain::kYes
232 : Domain::kNo;
233 fQuads.push_back(quad, quadType, {color, srcRect, domain, aaFlags});
Brian Salomond7065e72018-10-12 11:42:02 -0400234 fProxyCnt = 1;
235 fProxies[0] = {proxy.release(), 1};
Michael Ludwigc96fc372019-01-08 15:46:15 -0500236 auto bounds = quad.bounds(quadType);
Michael Ludwig6bee7762018-10-19 09:50:36 -0400237 this->setBounds(bounds, HasAABloat(aaType == GrAAType::kCoverage), IsZeroArea::kNo);
Michael Ludwigc96fc372019-01-08 15:46:15 -0500238 fDomain = static_cast<unsigned>(domain);
Brian Osman3d139a42018-11-19 10:42:10 -0500239 fWideColor = !SkPMColor4fFitsInBytes(color);
Brian Salomon7d94bb52018-10-12 14:37:19 -0400240 fCanSkipAllocatorGather =
241 static_cast<unsigned>(fProxies[0].fProxy->canSkipResourceAllocator());
Brian Salomond7065e72018-10-12 11:42:02 -0400242 }
243 TextureOp(const GrRenderTargetContext::TextureSetEntry set[], int cnt,
Brian Salomond003d222018-11-26 13:25:05 -0500244 GrSamplerState::Filter filter, GrAAType aaType, const SkMatrix& viewMatrix,
245 sk_sp<GrColorSpaceXform> textureColorSpaceXform)
Brian Salomond7065e72018-10-12 11:42:02 -0400246 : INHERITED(ClassID())
247 , fTextureColorSpaceXform(std::move(textureColorSpaceXform))
Brian Salomon0087c832018-10-15 14:48:20 -0400248 , fFilter(static_cast<unsigned>(filter))
Brian Salomond7065e72018-10-12 11:42:02 -0400249 , fFinalized(0) {
Brian Salomond7065e72018-10-12 11:42:02 -0400250 fProxyCnt = SkToUInt(cnt);
251 SkRect bounds = SkRectPriv::MakeLargestInverted();
Michael Ludwig6bee7762018-10-19 09:50:36 -0400252 GrAAType overallAAType = GrAAType::kNone; // aa type maximally compatible with all dst rects
Brian Salomon0087c832018-10-15 14:48:20 -0400253 bool mustFilter = false;
Brian Salomon7d94bb52018-10-12 14:37:19 -0400254 fCanSkipAllocatorGather = static_cast<unsigned>(true);
Michael Ludwig6bee7762018-10-19 09:50:36 -0400255 // All dst rects are transformed by the same view matrix, so their quad types are identical
256 GrQuadType quadType = GrQuadTypeForTransformedRect(viewMatrix);
Michael Ludwigc96fc372019-01-08 15:46:15 -0500257 fQuads.reserve(cnt, quadType);
258
Brian Salomond7065e72018-10-12 11:42:02 -0400259 for (unsigned p = 0; p < fProxyCnt; ++p) {
260 fProxies[p].fProxy = SkRef(set[p].fProxy.get());
261 fProxies[p].fQuadCnt = 1;
262 SkASSERT(fProxies[p].fProxy->textureType() == fProxies[0].fProxy->textureType());
263 SkASSERT(fProxies[p].fProxy->config() == fProxies[0].fProxy->config());
Brian Salomon7d94bb52018-10-12 14:37:19 -0400264 if (!fProxies[p].fProxy->canSkipResourceAllocator()) {
265 fCanSkipAllocatorGather = static_cast<unsigned>(false);
266 }
Brian Salomond7065e72018-10-12 11:42:02 -0400267 auto quad = GrPerspQuad(set[p].fDstRect, viewMatrix);
Michael Ludwigc96fc372019-01-08 15:46:15 -0500268 bounds.joinPossiblyEmptyRect(quad.bounds(quadType));
Michael Ludwig6bee7762018-10-19 09:50:36 -0400269 GrQuadAAFlags aaFlags;
270 // Don't update the overall aaType, might be inappropriate for some of the quads
271 GrAAType aaForQuad;
272 GrResolveAATypeForQuad(aaType, set[p].fAAFlags, quad, quadType, &aaForQuad, &aaFlags);
273 // Resolve sets aaForQuad to aaType or None, there is never a change between aa methods
274 SkASSERT(aaForQuad == GrAAType::kNone || aaForQuad == aaType);
275 if (overallAAType == GrAAType::kNone && aaForQuad != GrAAType::kNone) {
276 overallAAType = aaType;
Brian Salomond7065e72018-10-12 11:42:02 -0400277 }
Brian Salomon0087c832018-10-15 14:48:20 -0400278 if (!mustFilter && this->filter() != GrSamplerState::Filter::kNearest) {
Michael Ludwigc182b942018-11-16 10:27:51 -0500279 mustFilter = quadType != GrQuadType::kRect ||
Michael Ludwiga3c45c72019-01-17 17:26:48 -0500280 GrTextureOp::GetFilterHasEffect(viewMatrix, set[p].fSrcRect,
281 set[p].fDstRect);
Brian Salomon0087c832018-10-15 14:48:20 -0400282 }
Brian Salomond003d222018-11-26 13:25:05 -0500283 float alpha = SkTPin(set[p].fAlpha, 0.f, 1.f);
284 SkPMColor4f color{alpha, alpha, alpha, alpha};
Michael Ludwigc96fc372019-01-08 15:46:15 -0500285 fQuads.push_back(quad, quadType, {color, set[p].fSrcRect, Domain::kNo, aaFlags});
Brian Salomond7065e72018-10-12 11:42:02 -0400286 }
Michael Ludwig6bee7762018-10-19 09:50:36 -0400287 fAAType = static_cast<unsigned>(overallAAType);
Brian Salomon0087c832018-10-15 14:48:20 -0400288 if (!mustFilter) {
289 fFilter = static_cast<unsigned>(GrSamplerState::Filter::kNearest);
290 }
Brian Salomond7065e72018-10-12 11:42:02 -0400291 this->setBounds(bounds, HasAABloat(this->aaType() == GrAAType::kCoverage), IsZeroArea::kNo);
Brian Salomond7065e72018-10-12 11:42:02 -0400292 fDomain = static_cast<unsigned>(false);
Brian Salomon574d6162018-11-19 16:57:25 -0500293 fWideColor = static_cast<unsigned>(false);
Brian Salomon34169692017-08-28 15:32:01 -0400294 }
295
Brian Salomon574d6162018-11-19 16:57:25 -0500296 void tess(void* v, const VertexSpec& spec, const GrTextureProxy* proxy, int start,
297 int cnt) const {
Brian Salomond7065e72018-10-12 11:42:02 -0400298 TRACE_EVENT0("skia", TRACE_FUNC);
Brian Salomond7065e72018-10-12 11:42:02 -0400299 auto origin = proxy->origin();
300 const auto* texture = proxy->peekTexture();
Brian Salomon246bc3d2018-12-06 15:33:02 -0500301 float iw, ih, h;
302 if (proxy->textureType() == GrTextureType::kRectangle) {
303 iw = ih = 1.f;
304 h = texture->height();
305 } else {
306 iw = 1.f / texture->width();
307 ih = 1.f / texture->height();
308 h = 1.f;
309 }
Brian Salomon7eae3e02018-08-07 14:02:38 +0000310
Brian Salomond7065e72018-10-12 11:42:02 -0400311 for (int i = start; i < start + cnt; ++i) {
Michael Ludwigc96fc372019-01-08 15:46:15 -0500312 const GrPerspQuad& device = fQuads[i];
313 const ColorDomainAndAA& info = fQuads.metadata(i);
314
315 GrPerspQuad srcQuad = compute_src_quad(origin, info.fSrcRect, iw, ih, h);
Brian Salomon246bc3d2018-12-06 15:33:02 -0500316 SkRect domain =
Michael Ludwigc96fc372019-01-08 15:46:15 -0500317 compute_domain(info.domain(), this->filter(), origin, info.fSrcRect, iw, ih, h);
318 v = GrQuadPerEdgeAA::Tessellate(v, spec, device, info.fColor, srcQuad, domain,
319 info.aaFlags());
Brian Salomon17031a72018-05-22 14:14:07 -0400320 }
321 }
322
Brian Salomon34169692017-08-28 15:32:01 -0400323 void onPrepareDraws(Target* target) override {
Brian Salomond7065e72018-10-12 11:42:02 -0400324 TRACE_EVENT0("skia", TRACE_FUNC);
Michael Ludwigf995c052018-11-26 15:24:29 -0500325 GrQuadType quadType = GrQuadType::kRect;
Brian Salomonf7232642018-09-19 08:58:08 -0400326 Domain domain = Domain::kNo;
Brian Osman3d139a42018-11-19 10:42:10 -0500327 bool wideColor = false;
Brian Salomond7065e72018-10-12 11:42:02 -0400328 int numProxies = 0;
Brian Salomon4b8178f2018-10-12 13:18:27 -0400329 int numTotalQuads = 0;
Brian Salomond7065e72018-10-12 11:42:02 -0400330 auto textureType = fProxies[0].fProxy->textureType();
331 auto config = fProxies[0].fProxy->config();
Brian Salomonae7d7702018-10-14 15:05:45 -0400332 GrAAType aaType = this->aaType();
Brian Salomonf7232642018-09-19 08:58:08 -0400333 for (const auto& op : ChainRange<TextureOp>(this)) {
Michael Ludwigc96fc372019-01-08 15:46:15 -0500334 if (op.fQuads.quadType() > quadType) {
335 quadType = op.fQuads.quadType();
Michael Ludwigf995c052018-11-26 15:24:29 -0500336 }
Brian Salomonf7232642018-09-19 08:58:08 -0400337 if (op.fDomain) {
338 domain = Domain::kYes;
339 }
Brian Osman3d139a42018-11-19 10:42:10 -0500340 wideColor |= op.fWideColor;
Brian Salomond7065e72018-10-12 11:42:02 -0400341 numProxies += op.fProxyCnt;
342 for (unsigned p = 0; p < op.fProxyCnt; ++p) {
Brian Salomon4b8178f2018-10-12 13:18:27 -0400343 numTotalQuads += op.fProxies[p].fQuadCnt;
Brian Salomond7065e72018-10-12 11:42:02 -0400344 auto* proxy = op.fProxies[p].fProxy;
345 if (!proxy->instantiate(target->resourceProvider())) {
346 return;
347 }
348 SkASSERT(proxy->config() == config);
349 SkASSERT(proxy->textureType() == textureType);
Brian Salomonf7232642018-09-19 08:58:08 -0400350 }
Brian Salomonae7d7702018-10-14 15:05:45 -0400351 if (op.aaType() == GrAAType::kCoverage) {
352 SkASSERT(aaType == GrAAType::kCoverage || aaType == GrAAType::kNone);
353 aaType = GrAAType::kCoverage;
354 }
Brian Salomon34169692017-08-28 15:32:01 -0400355 }
Brian Salomon336ce7b2017-09-08 08:23:58 -0400356
Michael Ludwigf995c052018-11-26 15:24:29 -0500357 VertexSpec vertexSpec(quadType, wideColor ? ColorType::kHalf : ColorType::kByte,
Michael Ludwig93aeba02018-12-21 09:50:31 -0500358 GrQuadType::kRect, /* hasLocal */ true, domain, aaType,
359 /* alpha as coverage */ true);
Michael Ludwigc182b942018-11-16 10:27:51 -0500360
Greg Daniel7a82edf2018-12-04 10:54:34 -0500361 GrSamplerState samplerState = GrSamplerState(GrSamplerState::WrapMode::kClamp,
362 this->filter());
363 GrGpu* gpu = target->resourceProvider()->priv().gpu();
364 uint32_t extraSamplerKey = gpu->getExtraSamplerKeyForProgram(
365 samplerState, fProxies[0].fProxy->backendFormat());
366
Michael Ludwig467994d2018-12-03 14:58:31 +0000367 sk_sp<GrGeometryProcessor> gp = GrQuadPerEdgeAA::MakeTexturedProcessor(
368 vertexSpec, *target->caps().shaderCaps(),
Greg Daniel7a82edf2018-12-04 10:54:34 -0500369 textureType, config, samplerState, extraSamplerKey,
370 std::move(fTextureColorSpaceXform));
371
Brian Salomon34169692017-08-28 15:32:01 -0400372 GrPipeline::InitArgs args;
Brian Salomon34169692017-08-28 15:32:01 -0400373 args.fCaps = &target->caps();
374 args.fResourceProvider = target->resourceProvider();
Brian Salomon485b8c62018-01-12 15:11:06 -0500375 args.fFlags = 0;
Brian Salomonae7d7702018-10-14 15:05:45 -0400376 if (aaType == GrAAType::kMSAA) {
Brian Salomon485b8c62018-01-12 15:11:06 -0500377 args.fFlags |= GrPipeline::kHWAntialias_Flag;
378 }
379
Brian Salomon49348902018-06-26 09:12:38 -0400380 auto clip = target->detachAppliedClip();
Brian Salomonf7232642018-09-19 08:58:08 -0400381 // We'll use a dynamic state array for the GP textures when there are multiple ops.
382 // Otherwise, we use fixed dynamic state to specify the single op's proxy.
383 GrPipeline::DynamicStateArrays* dynamicStateArrays = nullptr;
384 GrPipeline::FixedDynamicState* fixedDynamicState;
Brian Salomond7065e72018-10-12 11:42:02 -0400385 if (numProxies > 1) {
386 dynamicStateArrays = target->allocDynamicStateArrays(numProxies, 1, false);
Brian Salomonf7232642018-09-19 08:58:08 -0400387 fixedDynamicState = target->allocFixedDynamicState(clip.scissorState().rect(), 0);
388 } else {
389 fixedDynamicState = target->allocFixedDynamicState(clip.scissorState().rect(), 1);
Brian Salomond7065e72018-10-12 11:42:02 -0400390 fixedDynamicState->fPrimitiveProcessorTextures[0] = fProxies[0].fProxy;
Brian Salomonf7232642018-09-19 08:58:08 -0400391 }
Brian Salomon49348902018-06-26 09:12:38 -0400392 const auto* pipeline =
393 target->allocPipeline(args, GrProcessorSet::MakeEmptySet(), std::move(clip));
Brian Salomon92be2f72018-06-19 14:33:47 -0400394
Michael Ludwigc182b942018-11-16 10:27:51 -0500395 size_t vertexSize = gp->vertexStride();
Brian Salomon92be2f72018-06-19 14:33:47 -0400396
Brian Salomond7065e72018-10-12 11:42:02 -0400397 GrMesh* meshes = target->allocMeshes(numProxies);
Brian Salomon12d22642019-01-29 14:38:50 -0500398 sk_sp<const GrBuffer> vbuffer;
Brian Salomon4b8178f2018-10-12 13:18:27 -0400399 int vertexOffsetInBuffer = 0;
Michael Ludwig93aeba02018-12-21 09:50:31 -0500400 int numQuadVerticesLeft = numTotalQuads * vertexSpec.verticesPerQuad();
Brian Salomon4b8178f2018-10-12 13:18:27 -0400401 int numAllocatedVertices = 0;
402 void* vdata = nullptr;
403
Brian Salomond7065e72018-10-12 11:42:02 -0400404 int m = 0;
Brian Salomonf7232642018-09-19 08:58:08 -0400405 for (const auto& op : ChainRange<TextureOp>(this)) {
Brian Salomond7065e72018-10-12 11:42:02 -0400406 int q = 0;
407 for (unsigned p = 0; p < op.fProxyCnt; ++p) {
408 int quadCnt = op.fProxies[p].fQuadCnt;
409 auto* proxy = op.fProxies[p].fProxy;
Michael Ludwig93aeba02018-12-21 09:50:31 -0500410 int meshVertexCnt = quadCnt * vertexSpec.verticesPerQuad();
Brian Salomon4b8178f2018-10-12 13:18:27 -0400411 if (numAllocatedVertices < meshVertexCnt) {
412 vdata = target->makeVertexSpaceAtLeast(
413 vertexSize, meshVertexCnt, numQuadVerticesLeft, &vbuffer,
414 &vertexOffsetInBuffer, &numAllocatedVertices);
415 SkASSERT(numAllocatedVertices <= numQuadVerticesLeft);
416 if (!vdata) {
417 SkDebugf("Could not allocate vertices\n");
418 return;
419 }
Brian Salomonf7232642018-09-19 08:58:08 -0400420 }
Brian Salomon4b8178f2018-10-12 13:18:27 -0400421 SkASSERT(numAllocatedVertices >= meshVertexCnt);
Brian Salomond7065e72018-10-12 11:42:02 -0400422
Michael Ludwigc182b942018-11-16 10:27:51 -0500423 op.tess(vdata, vertexSpec, proxy, q, quadCnt);
Brian Salomond7065e72018-10-12 11:42:02 -0400424
Michael Ludwig93aeba02018-12-21 09:50:31 -0500425 if (!GrQuadPerEdgeAA::ConfigureMeshIndices(target, &(meshes[m]), vertexSpec,
426 quadCnt)) {
427 SkDebugf("Could not allocate indices");
428 return;
Brian Salomond7065e72018-10-12 11:42:02 -0400429 }
Brian Salomon4b8178f2018-10-12 13:18:27 -0400430 meshes[m].setVertexData(vbuffer, vertexOffsetInBuffer);
Brian Salomond7065e72018-10-12 11:42:02 -0400431 if (dynamicStateArrays) {
432 dynamicStateArrays->fPrimitiveProcessorTextures[m] = proxy;
433 }
434 ++m;
Brian Salomon4b8178f2018-10-12 13:18:27 -0400435 numAllocatedVertices -= meshVertexCnt;
436 numQuadVerticesLeft -= meshVertexCnt;
437 vertexOffsetInBuffer += meshVertexCnt;
438 vdata = reinterpret_cast<char*>(vdata) + vertexSize * meshVertexCnt;
Brian Salomond7065e72018-10-12 11:42:02 -0400439 q += quadCnt;
Brian Salomonf7232642018-09-19 08:58:08 -0400440 }
Brian Salomon34169692017-08-28 15:32:01 -0400441 }
Brian Salomon4b8178f2018-10-12 13:18:27 -0400442 SkASSERT(!numQuadVerticesLeft);
443 SkASSERT(!numAllocatedVertices);
Brian Salomonf7232642018-09-19 08:58:08 -0400444 target->draw(std::move(gp), pipeline, fixedDynamicState, dynamicStateArrays, meshes,
Brian Salomond7065e72018-10-12 11:42:02 -0400445 numProxies);
Brian Salomon34169692017-08-28 15:32:01 -0400446 }
447
Brian Salomonf7232642018-09-19 08:58:08 -0400448 CombineResult onCombineIfPossible(GrOp* t, const GrCaps& caps) override {
Brian Salomond7065e72018-10-12 11:42:02 -0400449 TRACE_EVENT0("skia", TRACE_FUNC);
Brian Salomon34169692017-08-28 15:32:01 -0400450 const auto* that = t->cast<TextureOp>();
Brian Osman3ebd3542018-07-30 14:36:53 -0400451 if (!GrColorSpaceXform::Equals(fTextureColorSpaceXform.get(),
452 that->fTextureColorSpaceXform.get())) {
Brian Salomon7eae3e02018-08-07 14:02:38 +0000453 return CombineResult::kCannotCombine;
Brian Osman3ebd3542018-07-30 14:36:53 -0400454 }
Brian Salomonae7d7702018-10-14 15:05:45 -0400455 bool upgradeToCoverageAAOnMerge = false;
Brian Salomon485b8c62018-01-12 15:11:06 -0500456 if (this->aaType() != that->aaType()) {
Brian Salomonae7d7702018-10-14 15:05:45 -0400457 if (!((this->aaType() == GrAAType::kCoverage && that->aaType() == GrAAType::kNone) ||
458 (that->aaType() == GrAAType::kCoverage && this->aaType() == GrAAType::kNone))) {
459 return CombineResult::kCannotCombine;
460 }
461 upgradeToCoverageAAOnMerge = true;
Brian Salomonb5ef1f92018-01-11 11:46:21 -0500462 }
Brian Salomonf7232642018-09-19 08:58:08 -0400463 if (fFilter != that->fFilter) {
464 return CombineResult::kCannotCombine;
465 }
Brian Salomond7065e72018-10-12 11:42:02 -0400466 auto thisProxy = fProxies[0].fProxy;
467 auto thatProxy = that->fProxies[0].fProxy;
468 if (fProxyCnt > 1 || that->fProxyCnt > 1 ||
Brian Salomon588cec72018-11-14 13:56:37 -0500469 thisProxy->uniqueID() != thatProxy->uniqueID()) {
470 // We can't merge across different proxies. Check if 'this' can be chained with 'that'.
Greg Daniel45723ac2018-11-30 10:12:43 -0500471 if (GrTextureProxy::ProxiesAreCompatibleAsDynamicState(thisProxy, thatProxy) &&
Brian Salomonf7232642018-09-19 08:58:08 -0400472 caps.dynamicStateArrayGeometryProcessorTextureSupport()) {
473 return CombineResult::kMayChain;
474 }
Brian Salomon7eae3e02018-08-07 14:02:38 +0000475 return CombineResult::kCannotCombine;
Brian Salomon336ce7b2017-09-08 08:23:58 -0400476 }
Brian Salomond7065e72018-10-12 11:42:02 -0400477 fProxies[0].fQuadCnt += that->fQuads.count();
Michael Ludwigc96fc372019-01-08 15:46:15 -0500478 fQuads.concat(that->fQuads);
Brian Salomonb80ffee2018-05-23 16:39:39 -0400479 fDomain |= that->fDomain;
Brian Osman3d139a42018-11-19 10:42:10 -0500480 fWideColor |= that->fWideColor;
Brian Salomonae7d7702018-10-14 15:05:45 -0400481 if (upgradeToCoverageAAOnMerge) {
482 fAAType = static_cast<unsigned>(GrAAType::kCoverage);
483 }
Brian Salomon7eae3e02018-08-07 14:02:38 +0000484 return CombineResult::kMerged;
Brian Salomon34169692017-08-28 15:32:01 -0400485 }
486
Brian Salomon485b8c62018-01-12 15:11:06 -0500487 GrAAType aaType() const { return static_cast<GrAAType>(fAAType); }
Brian Salomon0087c832018-10-15 14:48:20 -0400488 GrSamplerState::Filter filter() const { return static_cast<GrSamplerState::Filter>(fFilter); }
Brian Salomonb5ef1f92018-01-11 11:46:21 -0500489
Michael Ludwigc96fc372019-01-08 15:46:15 -0500490 struct ColorDomainAndAA {
491 // Special constructor to convert enums into the packed bits, which should not delete
492 // the implicit move constructor (but it does require us to declare an empty ctor for
493 // use with the GrTQuadList).
494 ColorDomainAndAA(const SkPMColor4f& color, const SkRect& srcRect,
495 Domain hasDomain, GrQuadAAFlags aaFlags)
496 : fColor(color)
497 , fSrcRect(srcRect)
498 , fHasDomain(static_cast<unsigned>(hasDomain))
Brian Salomon2213ee92018-10-02 10:44:21 -0400499 , fAAFlags(static_cast<unsigned>(aaFlags)) {
Michael Ludwigc96fc372019-01-08 15:46:15 -0500500 SkASSERT(fHasDomain == static_cast<unsigned>(hasDomain));
Brian Salomon2213ee92018-10-02 10:44:21 -0400501 SkASSERT(fAAFlags == static_cast<unsigned>(aaFlags));
502 }
Michael Ludwigc96fc372019-01-08 15:46:15 -0500503 ColorDomainAndAA() = default;
Michael Ludwig23d8943e2019-01-04 14:51:40 +0000504
Michael Ludwig23d8943e2019-01-04 14:51:40 +0000505 SkPMColor4f fColor;
Michael Ludwigc96fc372019-01-08 15:46:15 -0500506 SkRect fSrcRect;
Michael Ludwig23d8943e2019-01-04 14:51:40 +0000507 unsigned fHasDomain : 1;
508 unsigned fAAFlags : 4;
Michael Ludwigc96fc372019-01-08 15:46:15 -0500509
510 Domain domain() const { return Domain(fHasDomain); }
511 GrQuadAAFlags aaFlags() const { return static_cast<GrQuadAAFlags>(fAAFlags); }
Brian Salomon34169692017-08-28 15:32:01 -0400512 };
Brian Salomond7065e72018-10-12 11:42:02 -0400513 struct Proxy {
514 GrTextureProxy* fProxy;
515 int fQuadCnt;
516 };
Michael Ludwigc96fc372019-01-08 15:46:15 -0500517 GrTQuadList<ColorDomainAndAA> fQuads;
Brian Osman3ebd3542018-07-30 14:36:53 -0400518 sk_sp<GrColorSpaceXform> fTextureColorSpaceXform;
Brian Salomon0087c832018-10-15 14:48:20 -0400519 unsigned fFilter : 2;
Brian Salomon485b8c62018-01-12 15:11:06 -0500520 unsigned fAAType : 2;
Brian Salomonb80ffee2018-05-23 16:39:39 -0400521 unsigned fDomain : 1;
Brian Osman3d139a42018-11-19 10:42:10 -0500522 unsigned fWideColor : 1;
Brian Salomon34169692017-08-28 15:32:01 -0400523 // Used to track whether fProxy is ref'ed or has a pending IO after finalize() is called.
Brian Salomonb5ef1f92018-01-11 11:46:21 -0500524 unsigned fFinalized : 1;
Brian Salomon7d94bb52018-10-12 14:37:19 -0400525 unsigned fCanSkipAllocatorGather : 1;
Michael Ludwigc96fc372019-01-08 15:46:15 -0500526 unsigned fProxyCnt : 32 - 8;
Brian Salomond7065e72018-10-12 11:42:02 -0400527 Proxy fProxies[1];
Brian Salomon336ce7b2017-09-08 08:23:58 -0400528
Michael Ludwigf995c052018-11-26 15:24:29 -0500529 static_assert(kGrQuadTypeCount <= 4, "GrQuadType does not fit in 2 bits");
530
Brian Salomon34169692017-08-28 15:32:01 -0400531 typedef GrMeshDrawOp INHERITED;
532};
533
534} // anonymous namespace
535
536namespace GrTextureOp {
537
Robert Phillips7c525e62018-06-12 10:11:12 -0400538std::unique_ptr<GrDrawOp> Make(GrContext* context,
539 sk_sp<GrTextureProxy> proxy,
540 GrSamplerState::Filter filter,
Brian Osman3d139a42018-11-19 10:42:10 -0500541 const SkPMColor4f& color,
Robert Phillips7c525e62018-06-12 10:11:12 -0400542 const SkRect& srcRect,
543 const SkRect& dstRect,
544 GrAAType aaType,
Brian Salomon2213ee92018-10-02 10:44:21 -0400545 GrQuadAAFlags aaFlags,
Robert Phillips7c525e62018-06-12 10:11:12 -0400546 SkCanvas::SrcRectConstraint constraint,
547 const SkMatrix& viewMatrix,
Brian Osman3d139a42018-11-19 10:42:10 -0500548 sk_sp<GrColorSpaceXform> textureColorSpaceXform) {
Robert Phillips7c525e62018-06-12 10:11:12 -0400549 return TextureOp::Make(context, std::move(proxy), filter, color, srcRect, dstRect, aaType,
Brian Osman3d139a42018-11-19 10:42:10 -0500550 aaFlags, constraint, viewMatrix, std::move(textureColorSpaceXform));
Brian Salomon34169692017-08-28 15:32:01 -0400551}
552
Brian Salomond7065e72018-10-12 11:42:02 -0400553std::unique_ptr<GrDrawOp> Make(GrContext* context,
554 const GrRenderTargetContext::TextureSetEntry set[],
555 int cnt,
556 GrSamplerState::Filter filter,
Brian Salomond7065e72018-10-12 11:42:02 -0400557 GrAAType aaType,
558 const SkMatrix& viewMatrix,
Brian Osman3d139a42018-11-19 10:42:10 -0500559 sk_sp<GrColorSpaceXform> textureColorSpaceXform) {
Brian Salomond003d222018-11-26 13:25:05 -0500560 return TextureOp::Make(context, set, cnt, filter, aaType, viewMatrix,
Brian Osman3d139a42018-11-19 10:42:10 -0500561 std::move(textureColorSpaceXform));
Brian Salomond7065e72018-10-12 11:42:02 -0400562}
563
Michael Ludwiga3c45c72019-01-17 17:26:48 -0500564bool GetFilterHasEffect(const SkMatrix& viewMatrix, const SkRect& srcRect, const SkRect& dstRect) {
565 // Hypothetically we could disable bilerp filtering when flipping or rotating 90 degrees, but
566 // that makes the math harder and we don't want to increase the overhead of the checks
567 if (!viewMatrix.isScaleTranslate() ||
568 viewMatrix.getScaleX() < 0.0f || viewMatrix.getScaleY() < 0.0f) {
569 return true;
570 }
571
572 // Given the matrix conditions ensured above, this computes the device space coordinates for
573 // the top left corner of dstRect and its size.
574 SkScalar dw = viewMatrix.getScaleX() * dstRect.width();
575 SkScalar dh = viewMatrix.getScaleY() * dstRect.height();
576 SkScalar dl = viewMatrix.getScaleX() * dstRect.fLeft + viewMatrix.getTranslateX();
577 SkScalar dt = viewMatrix.getScaleY() * dstRect.fTop + viewMatrix.getTranslateY();
578
579 // Disable filtering when there is no scaling of the src rect and the src rect and dst rect
580 // align fractionally. If we allow inverted src rects this logic needs to consider that.
581 SkASSERT(srcRect.isSorted());
582 return dw != srcRect.width() || dh != srcRect.height() ||
583 SkScalarFraction(dl) != SkScalarFraction(srcRect.fLeft) ||
584 SkScalarFraction(dt) != SkScalarFraction(srcRect.fTop);
585}
586
Brian Salomon34169692017-08-28 15:32:01 -0400587} // namespace GrTextureOp
588
589#if GR_TEST_UTILS
590#include "GrContext.h"
Robert Phillips1afd4cd2018-01-08 13:40:32 -0500591#include "GrContextPriv.h"
Robert Phillips0bd24dc2018-01-16 08:06:32 -0500592#include "GrProxyProvider.h"
Brian Salomon34169692017-08-28 15:32:01 -0400593
594GR_DRAW_OP_TEST_DEFINE(TextureOp) {
595 GrSurfaceDesc desc;
596 desc.fConfig = kRGBA_8888_GrPixelConfig;
597 desc.fHeight = random->nextULessThan(90) + 10;
598 desc.fWidth = random->nextULessThan(90) + 10;
Brian Salomon2a4f9832018-03-03 22:43:43 -0500599 auto origin = random->nextBool() ? kTopLeft_GrSurfaceOrigin : kBottomLeft_GrSurfaceOrigin;
Greg Daniel09c94002018-06-08 22:11:51 +0000600 GrMipMapped mipMapped = random->nextBool() ? GrMipMapped::kYes : GrMipMapped::kNo;
601 SkBackingFit fit = SkBackingFit::kExact;
602 if (mipMapped == GrMipMapped::kNo) {
603 fit = random->nextBool() ? SkBackingFit::kApprox : SkBackingFit::kExact;
604 }
Robert Phillips0bd24dc2018-01-16 08:06:32 -0500605
Greg Daniel4065d452018-11-16 15:43:41 -0500606 const GrBackendFormat format =
Robert Phillips9da87e02019-02-04 13:26:26 -0500607 context->priv().caps()->getBackendFormatFromColorType(kRGBA_8888_SkColorType);
Greg Daniel4065d452018-11-16 15:43:41 -0500608
Robert Phillips9da87e02019-02-04 13:26:26 -0500609 GrProxyProvider* proxyProvider = context->priv().proxyProvider();
Greg Daniel4065d452018-11-16 15:43:41 -0500610 sk_sp<GrTextureProxy> proxy = proxyProvider->createProxy(format, desc, origin, mipMapped, fit,
Greg Daniel09c94002018-06-08 22:11:51 +0000611 SkBudgeted::kNo,
612 GrInternalSurfaceFlags::kNone);
Robert Phillips0bd24dc2018-01-16 08:06:32 -0500613
Brian Salomon34169692017-08-28 15:32:01 -0400614 SkRect rect = GrTest::TestRect(random);
615 SkRect srcRect;
616 srcRect.fLeft = random->nextRangeScalar(0.f, proxy->width() / 2.f);
617 srcRect.fRight = random->nextRangeScalar(0.f, proxy->width()) + proxy->width() / 2.f;
618 srcRect.fTop = random->nextRangeScalar(0.f, proxy->height() / 2.f);
619 srcRect.fBottom = random->nextRangeScalar(0.f, proxy->height()) + proxy->height() / 2.f;
620 SkMatrix viewMatrix = GrTest::TestMatrixPreservesRightAngles(random);
Brian Osman3d139a42018-11-19 10:42:10 -0500621 SkPMColor4f color = SkPMColor4f::FromBytes_RGBA(SkColorToPremulGrColor(random->nextU()));
Brian Salomon2bbdcc42017-09-07 12:36:34 -0400622 GrSamplerState::Filter filter = (GrSamplerState::Filter)random->nextULessThan(
623 static_cast<uint32_t>(GrSamplerState::Filter::kMipMap) + 1);
Greg Daniel09c94002018-06-08 22:11:51 +0000624 while (mipMapped == GrMipMapped::kNo && filter == GrSamplerState::Filter::kMipMap) {
625 filter = (GrSamplerState::Filter)random->nextULessThan(
626 static_cast<uint32_t>(GrSamplerState::Filter::kMipMap) + 1);
627 }
Brian Osman3ebd3542018-07-30 14:36:53 -0400628 auto texXform = GrTest::TestColorXform(random);
Brian Salomon485b8c62018-01-12 15:11:06 -0500629 GrAAType aaType = GrAAType::kNone;
630 if (random->nextBool()) {
631 aaType = (fsaaType == GrFSAAType::kUnifiedMSAA) ? GrAAType::kMSAA : GrAAType::kCoverage;
632 }
Brian Salomon2213ee92018-10-02 10:44:21 -0400633 GrQuadAAFlags aaFlags = GrQuadAAFlags::kNone;
634 aaFlags |= random->nextBool() ? GrQuadAAFlags::kLeft : GrQuadAAFlags::kNone;
635 aaFlags |= random->nextBool() ? GrQuadAAFlags::kTop : GrQuadAAFlags::kNone;
636 aaFlags |= random->nextBool() ? GrQuadAAFlags::kRight : GrQuadAAFlags::kNone;
637 aaFlags |= random->nextBool() ? GrQuadAAFlags::kBottom : GrQuadAAFlags::kNone;
Brian Salomonb80ffee2018-05-23 16:39:39 -0400638 auto constraint = random->nextBool() ? SkCanvas::kStrict_SrcRectConstraint
639 : SkCanvas::kFast_SrcRectConstraint;
Robert Phillips7c525e62018-06-12 10:11:12 -0400640 return GrTextureOp::Make(context, std::move(proxy), filter, color, srcRect, rect, aaType,
Brian Osman3d139a42018-11-19 10:42:10 -0500641 aaFlags, constraint, viewMatrix, std::move(texXform));
Brian Salomon34169692017-08-28 15:32:01 -0400642}
643
644#endif