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 | |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 8 | #include <new> |
Brian Salomon | f19f9ca | 2019-09-18 15:54:26 -0400 | [diff] [blame] | 9 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 10 | #include "include/core/SkPoint.h" |
| 11 | #include "include/core/SkPoint3.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 12 | #include "include/private/GrRecordingContext.h" |
Michael Ludwig | 22429f9 | 2019-06-27 10:44:48 -0400 | [diff] [blame] | 13 | #include "include/private/SkFloatingPoint.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 14 | #include "include/private/SkTo.h" |
| 15 | #include "src/core/SkMathPriv.h" |
| 16 | #include "src/core/SkMatrixPriv.h" |
| 17 | #include "src/core/SkRectPriv.h" |
| 18 | #include "src/gpu/GrAppliedClip.h" |
| 19 | #include "src/gpu/GrCaps.h" |
| 20 | #include "src/gpu/GrDrawOpTest.h" |
| 21 | #include "src/gpu/GrGeometryProcessor.h" |
| 22 | #include "src/gpu/GrGpu.h" |
| 23 | #include "src/gpu/GrMemoryPool.h" |
| 24 | #include "src/gpu/GrOpFlushState.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 25 | #include "src/gpu/GrRecordingContextPriv.h" |
| 26 | #include "src/gpu/GrResourceProvider.h" |
| 27 | #include "src/gpu/GrResourceProviderPriv.h" |
| 28 | #include "src/gpu/GrShaderCaps.h" |
Greg Daniel | 456f9b5 | 2020-03-05 19:14:18 +0000 | [diff] [blame] | 29 | #include "src/gpu/GrTexture.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 30 | #include "src/gpu/GrTexturePriv.h" |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame] | 31 | #include "src/gpu/GrTextureProxy.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 32 | #include "src/gpu/SkGr.h" |
Brian Osman | 6f5e940 | 2020-01-22 10:39:31 -0500 | [diff] [blame] | 33 | #include "src/gpu/effects/generated/GrClampFragmentProcessor.h" |
Michael Ludwig | fd4f4df | 2019-05-29 09:51:09 -0400 | [diff] [blame] | 34 | #include "src/gpu/geometry/GrQuad.h" |
Michael Ludwig | 425eb45 | 2019-06-27 10:13:27 -0400 | [diff] [blame] | 35 | #include "src/gpu/geometry/GrQuadBuffer.h" |
Michael Ludwig | 0f80902 | 2019-06-04 09:14:37 -0400 | [diff] [blame] | 36 | #include "src/gpu/geometry/GrQuadUtils.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 37 | #include "src/gpu/glsl/GrGLSLVarying.h" |
Michael Ludwig | 22429f9 | 2019-06-27 10:44:48 -0400 | [diff] [blame] | 38 | #include "src/gpu/ops/GrFillRectOp.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 39 | #include "src/gpu/ops/GrMeshDrawOp.h" |
| 40 | #include "src/gpu/ops/GrQuadPerEdgeAA.h" |
Robert Phillips | 3968fcb | 2019-12-05 16:40:31 -0500 | [diff] [blame] | 41 | #include "src/gpu/ops/GrSimpleMeshDrawOpHelper.h" |
Brian Salomon | f19f9ca | 2019-09-18 15:54:26 -0400 | [diff] [blame] | 42 | #include "src/gpu/ops/GrTextureOp.h" |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 43 | |
| 44 | namespace { |
| 45 | |
Brian Salomon | 2432d06 | 2020-04-16 20:48:09 -0400 | [diff] [blame^] | 46 | using Subset = GrQuadPerEdgeAA::Subset; |
Michael Ludwig | c182b94 | 2018-11-16 10:27:51 -0500 | [diff] [blame] | 47 | using VertexSpec = GrQuadPerEdgeAA::VertexSpec; |
Brian Osman | 3d139a4 | 2018-11-19 10:42:10 -0500 | [diff] [blame] | 48 | using ColorType = GrQuadPerEdgeAA::ColorType; |
Brian Salomon | b80ffee | 2018-05-23 16:39:39 -0400 | [diff] [blame] | 49 | |
Michael Ludwig | 22429f9 | 2019-06-27 10:44:48 -0400 | [diff] [blame] | 50 | // Extracts lengths of vertical and horizontal edges of axis-aligned quad. "width" is the edge |
| 51 | // between v0 and v2 (or v1 and v3), "height" is the edge between v0 and v1 (or v2 and v3). |
| 52 | static SkSize axis_aligned_quad_size(const GrQuad& quad) { |
| 53 | SkASSERT(quad.quadType() == GrQuad::Type::kAxisAligned); |
| 54 | // Simplification of regular edge length equation, since it's axis aligned and can avoid sqrt |
| 55 | float dw = sk_float_abs(quad.x(2) - quad.x(0)) + sk_float_abs(quad.y(2) - quad.y(0)); |
| 56 | float dh = sk_float_abs(quad.x(1) - quad.x(0)) + sk_float_abs(quad.y(1) - quad.y(0)); |
| 57 | return {dw, dh}; |
| 58 | } |
| 59 | |
| 60 | static bool filter_has_effect(const GrQuad& srcQuad, const GrQuad& dstQuad) { |
| 61 | // If not axis-aligned in src or dst, then always say it has an effect |
| 62 | if (srcQuad.quadType() != GrQuad::Type::kAxisAligned || |
| 63 | dstQuad.quadType() != GrQuad::Type::kAxisAligned) { |
| 64 | return true; |
| 65 | } |
| 66 | |
| 67 | SkRect srcRect; |
| 68 | SkRect dstRect; |
| 69 | if (srcQuad.asRect(&srcRect) && dstQuad.asRect(&dstRect)) { |
| 70 | // Disable filtering when there is no scaling (width and height are the same), and the |
| 71 | // top-left corners have the same fraction (so src and dst snap to the pixel grid |
| 72 | // identically). |
| 73 | SkASSERT(srcRect.isSorted()); |
| 74 | return srcRect.width() != dstRect.width() || srcRect.height() != dstRect.height() || |
| 75 | SkScalarFraction(srcRect.fLeft) != SkScalarFraction(dstRect.fLeft) || |
| 76 | SkScalarFraction(srcRect.fTop) != SkScalarFraction(dstRect.fTop); |
| 77 | } else { |
| 78 | // Although the quads are axis-aligned, the local coordinate system is transformed such |
| 79 | // that fractionally-aligned sample centers will not align with the device coordinate system |
| 80 | // So disable filtering when edges are the same length and both srcQuad and dstQuad |
| 81 | // 0th vertex is integer aligned. |
| 82 | if (SkScalarIsInt(srcQuad.x(0)) && SkScalarIsInt(srcQuad.y(0)) && |
| 83 | SkScalarIsInt(dstQuad.x(0)) && SkScalarIsInt(dstQuad.y(0))) { |
| 84 | // Extract edge lengths |
| 85 | SkSize srcSize = axis_aligned_quad_size(srcQuad); |
| 86 | SkSize dstSize = axis_aligned_quad_size(dstQuad); |
| 87 | return srcSize.fWidth != dstSize.fWidth || srcSize.fHeight != dstSize.fHeight; |
| 88 | } else { |
| 89 | return true; |
| 90 | } |
| 91 | } |
| 92 | } |
| 93 | |
Michael Ludwig | 119ac6d | 2019-11-21 09:26:46 -0500 | [diff] [blame] | 94 | // Describes function for normalizing src coords: [x * iw, y * ih + yOffset] can represent |
| 95 | // regular and rectangular textures, w/ or w/o origin correction. |
| 96 | struct NormalizationParams { |
| 97 | float fIW; // 1 / width of texture, or 1.0 for texture rectangles |
| 98 | float fIH; // 1 / height of texture, or 1.0 for tex rects, X -1 if bottom-left origin |
| 99 | float fYOffset; // 0 for top-left origin, height of [normalized] tex if bottom-left |
| 100 | }; |
Michael Ludwig | adb12e7 | 2019-12-04 16:19:18 -0500 | [diff] [blame] | 101 | static NormalizationParams proxy_normalization_params(const GrSurfaceProxy* proxy, |
| 102 | GrSurfaceOrigin origin) { |
Michael Ludwig | 119ac6d | 2019-11-21 09:26:46 -0500 | [diff] [blame] | 103 | // Whether or not the proxy is instantiated, this is the size its texture will be, so we can |
| 104 | // normalize the src coordinates up front. |
Michael Ludwig | adb12e7 | 2019-12-04 16:19:18 -0500 | [diff] [blame] | 105 | SkISize dimensions = proxy->backingStoreDimensions(); |
Michael Ludwig | 119ac6d | 2019-11-21 09:26:46 -0500 | [diff] [blame] | 106 | float iw, ih, h; |
Michael Ludwig | adb12e7 | 2019-12-04 16:19:18 -0500 | [diff] [blame] | 107 | if (proxy->backendFormat().textureType() == GrTextureType::kRectangle) { |
Michael Ludwig | 119ac6d | 2019-11-21 09:26:46 -0500 | [diff] [blame] | 108 | iw = ih = 1.f; |
| 109 | h = dimensions.height(); |
| 110 | } else { |
| 111 | iw = 1.f / dimensions.width(); |
| 112 | ih = 1.f / dimensions.height(); |
| 113 | h = 1.f; |
| 114 | } |
| 115 | |
Michael Ludwig | adb12e7 | 2019-12-04 16:19:18 -0500 | [diff] [blame] | 116 | if (origin == kBottomLeft_GrSurfaceOrigin) { |
Michael Ludwig | 119ac6d | 2019-11-21 09:26:46 -0500 | [diff] [blame] | 117 | return {iw, -ih, h}; |
| 118 | } else { |
| 119 | return {iw, ih, 0.0f}; |
| 120 | } |
| 121 | } |
| 122 | |
Brian Salomon | 2432d06 | 2020-04-16 20:48:09 -0400 | [diff] [blame^] | 123 | static SkRect inset_subset_for_bilerp(const NormalizationParams& params, const SkRect& subsetRect) { |
Michael Ludwig | 119ac6d | 2019-11-21 09:26:46 -0500 | [diff] [blame] | 124 | // Normalized pixel size is also equal to iw and ih, so the insets for bilerp are just |
Brian Salomon | 2432d06 | 2020-04-16 20:48:09 -0400 | [diff] [blame^] | 125 | // in those units and can be applied safely after normalization. However, if the subset is |
Michael Ludwig | 119ac6d | 2019-11-21 09:26:46 -0500 | [diff] [blame] | 126 | // smaller than a texel, it should clamp to the center of that axis. |
Brian Salomon | 2432d06 | 2020-04-16 20:48:09 -0400 | [diff] [blame^] | 127 | float dw = subsetRect.width() < params.fIW ? subsetRect.width() : params.fIW; |
| 128 | float dh = subsetRect.height() < params.fIH ? subsetRect.height() : params.fIH; |
| 129 | return subsetRect.makeInset(0.5f * dw, 0.5f * dh); |
Michael Ludwig | 119ac6d | 2019-11-21 09:26:46 -0500 | [diff] [blame] | 130 | } |
| 131 | |
Brian Salomon | 2432d06 | 2020-04-16 20:48:09 -0400 | [diff] [blame^] | 132 | // Normalize the subset. If 'subsetRect' is null, it is assumed no subset constraint is desired, |
Michael Ludwig | 7c6a4a8 | 2020-02-07 10:14:26 -0500 | [diff] [blame] | 133 | // so a sufficiently large rect is returned even if the quad ends up batched with an op that uses |
Brian Salomon | 2432d06 | 2020-04-16 20:48:09 -0400 | [diff] [blame^] | 134 | // subsets overall. |
| 135 | static SkRect normalize_subset(GrSamplerState::Filter filter, |
Michael Ludwig | 119ac6d | 2019-11-21 09:26:46 -0500 | [diff] [blame] | 136 | const NormalizationParams& params, |
Brian Salomon | 2432d06 | 2020-04-16 20:48:09 -0400 | [diff] [blame^] | 137 | const SkRect* subsetRect) { |
Brian Salomon | 246bc3d | 2018-12-06 15:33:02 -0500 | [diff] [blame] | 138 | static constexpr SkRect kLargeRect = {-100000, -100000, 1000000, 1000000}; |
Brian Salomon | 2432d06 | 2020-04-16 20:48:09 -0400 | [diff] [blame^] | 139 | if (!subsetRect) { |
| 140 | // Either the quad has no subset constraint and is batched with a subset constrained op |
| 141 | // (in which case we want a subset that doesn't restrict normalized tex coords), or the |
| 142 | // entire op doesn't use the subset, in which case the returned value is ignored. |
Michael Ludwig | 119ac6d | 2019-11-21 09:26:46 -0500 | [diff] [blame] | 143 | return kLargeRect; |
Michael Ludwig | 460eb5e | 2018-10-29 11:09:29 -0400 | [diff] [blame] | 144 | } |
| 145 | |
Brian Salomon | 2432d06 | 2020-04-16 20:48:09 -0400 | [diff] [blame^] | 146 | auto ltrb = skvx::Vec<4, float>::Load(subsetRect); |
Michael Ludwig | 119ac6d | 2019-11-21 09:26:46 -0500 | [diff] [blame] | 147 | // Normalize and offset |
| 148 | ltrb = mad(ltrb, {params.fIW, params.fIH, params.fIW, params.fIH}, |
| 149 | {0.f, params.fYOffset, 0.f, params.fYOffset}); |
| 150 | if (params.fIH < 0.f) { |
| 151 | // Flip top and bottom to keep the rect sorted when loaded back to SkRect. |
| 152 | ltrb = skvx::shuffle<0, 3, 2, 1>(ltrb); |
Michael Ludwig | 460eb5e | 2018-10-29 11:09:29 -0400 | [diff] [blame] | 153 | } |
| 154 | |
Michael Ludwig | 119ac6d | 2019-11-21 09:26:46 -0500 | [diff] [blame] | 155 | SkRect out; |
| 156 | ltrb.store(&out); |
Michael Ludwig | 119ac6d | 2019-11-21 09:26:46 -0500 | [diff] [blame] | 157 | return out; |
Michael Ludwig | 460eb5e | 2018-10-29 11:09:29 -0400 | [diff] [blame] | 158 | } |
| 159 | |
Michael Ludwig | 009b92e | 2019-02-15 16:03:53 -0500 | [diff] [blame] | 160 | // Normalizes logical src coords and corrects for origin |
Michael Ludwig | 119ac6d | 2019-11-21 09:26:46 -0500 | [diff] [blame] | 161 | static void normalize_src_quad(const NormalizationParams& params, |
| 162 | GrQuad* srcQuad) { |
Michael Ludwig | 009b92e | 2019-02-15 16:03:53 -0500 | [diff] [blame] | 163 | // The src quad should not have any perspective |
Michael Ludwig | 119ac6d | 2019-11-21 09:26:46 -0500 | [diff] [blame] | 164 | SkASSERT(!srcQuad->hasPerspective()); |
| 165 | skvx::Vec<4, float> xs = srcQuad->x4f() * params.fIW; |
| 166 | skvx::Vec<4, float> ys = mad(srcQuad->y4f(), params.fIH, params.fYOffset); |
| 167 | xs.store(srcQuad->xs()); |
| 168 | ys.store(srcQuad->ys()); |
Michael Ludwig | 009b92e | 2019-02-15 16:03:53 -0500 | [diff] [blame] | 169 | } |
Michael Ludwig | 460eb5e | 2018-10-29 11:09:29 -0400 | [diff] [blame] | 170 | |
Michael Ludwig | 379e496 | 2019-12-06 13:21:26 -0500 | [diff] [blame] | 171 | // Count the number of proxy runs in the entry set. This usually is already computed by |
| 172 | // SkGpuDevice, but when the BatchLengthLimiter chops the set up it must determine a new proxy count |
| 173 | // for each split. |
| 174 | static int proxy_run_count(const GrRenderTargetContext::TextureSetEntry set[], int count) { |
| 175 | int actualProxyRunCount = 0; |
| 176 | const GrSurfaceProxy* lastProxy = nullptr; |
| 177 | for (int i = 0; i < count; ++i) { |
| 178 | if (set[i].fProxyView.proxy() != lastProxy) { |
| 179 | actualProxyRunCount++; |
| 180 | lastProxy = set[i].fProxyView.proxy(); |
| 181 | } |
| 182 | } |
| 183 | return actualProxyRunCount; |
| 184 | } |
| 185 | |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 186 | /** |
| 187 | * Op that implements GrTextureOp::Make. It draws textured quads. Each quad can modulate against a |
| 188 | * the texture by color. The blend with the destination is always src-over. The edges are non-AA. |
| 189 | */ |
| 190 | class TextureOp final : public GrMeshDrawOp { |
| 191 | public: |
Robert Phillips | b97da53 | 2019-02-12 15:24:12 -0500 | [diff] [blame] | 192 | static std::unique_ptr<GrDrawOp> Make(GrRecordingContext* context, |
Greg Daniel | 549325c | 2019-10-30 16:19:20 -0400 | [diff] [blame] | 193 | GrSurfaceProxyView proxyView, |
Michael Ludwig | 22429f9 | 2019-06-27 10:44:48 -0400 | [diff] [blame] | 194 | sk_sp<GrColorSpaceXform> textureXform, |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 195 | GrSamplerState::Filter filter, |
Brian Osman | 3d139a4 | 2018-11-19 10:42:10 -0500 | [diff] [blame] | 196 | const SkPMColor4f& color, |
Brian Salomon | f19f9ca | 2019-09-18 15:54:26 -0400 | [diff] [blame] | 197 | GrTextureOp::Saturate saturate, |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 198 | GrAAType aaType, |
Michael Ludwig | 6b45c5d | 2020-02-07 09:56:38 -0500 | [diff] [blame] | 199 | DrawQuad* quad, |
Brian Salomon | 2432d06 | 2020-04-16 20:48:09 -0400 | [diff] [blame^] | 200 | const SkRect* subset) { |
Michael Ludwig | 009b92e | 2019-02-15 16:03:53 -0500 | [diff] [blame] | 201 | GrOpMemoryPool* pool = context->priv().opMemoryPool(); |
Greg Daniel | 549325c | 2019-10-30 16:19:20 -0400 | [diff] [blame] | 202 | return pool->allocate<TextureOp>(std::move(proxyView), std::move(textureXform), filter, |
Brian Salomon | 2432d06 | 2020-04-16 20:48:09 -0400 | [diff] [blame^] | 203 | color, saturate, aaType, quad, subset); |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 204 | } |
Robert Phillips | e837e61 | 2019-11-15 11:02:50 -0500 | [diff] [blame] | 205 | |
Robert Phillips | b97da53 | 2019-02-12 15:24:12 -0500 | [diff] [blame] | 206 | static std::unique_ptr<GrDrawOp> Make(GrRecordingContext* context, |
Michael Ludwig | adb12e7 | 2019-12-04 16:19:18 -0500 | [diff] [blame] | 207 | GrRenderTargetContext::TextureSetEntry set[], |
Brian Salomon | f19f9ca | 2019-09-18 15:54:26 -0400 | [diff] [blame] | 208 | int cnt, |
Michael Ludwig | 379e496 | 2019-12-06 13:21:26 -0500 | [diff] [blame] | 209 | int proxyRunCnt, |
Brian Salomon | f19f9ca | 2019-09-18 15:54:26 -0400 | [diff] [blame] | 210 | GrSamplerState::Filter filter, |
| 211 | GrTextureOp::Saturate saturate, |
| 212 | GrAAType aaType, |
Michael Ludwig | 31ba718 | 2019-04-03 10:38:06 -0400 | [diff] [blame] | 213 | SkCanvas::SrcRectConstraint constraint, |
Brian Salomon | d003d22 | 2018-11-26 13:25:05 -0500 | [diff] [blame] | 214 | const SkMatrix& viewMatrix, |
Brian Osman | 3d139a4 | 2018-11-19 10:42:10 -0500 | [diff] [blame] | 215 | sk_sp<GrColorSpaceXform> textureColorSpaceXform) { |
Michael Ludwig | 379e496 | 2019-12-06 13:21:26 -0500 | [diff] [blame] | 216 | // Allocate size based on proxyRunCnt, since that determines number of ViewCountPairs. |
| 217 | SkASSERT(proxyRunCnt <= cnt); |
| 218 | |
| 219 | size_t size = sizeof(TextureOp) + sizeof(ViewCountPair) * (proxyRunCnt - 1); |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 220 | GrOpMemoryPool* pool = context->priv().opMemoryPool(); |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 221 | void* mem = pool->allocate(size); |
Michael Ludwig | 379e496 | 2019-12-06 13:21:26 -0500 | [diff] [blame] | 222 | return std::unique_ptr<GrDrawOp>( |
| 223 | new (mem) TextureOp(set, cnt, proxyRunCnt, filter, saturate, aaType, constraint, |
| 224 | viewMatrix, std::move(textureColorSpaceXform))); |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 225 | } |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 226 | |
Brian Salomon | 336ce7b | 2017-09-08 08:23:58 -0400 | [diff] [blame] | 227 | ~TextureOp() override { |
Michael Ludwig | adb12e7 | 2019-12-04 16:19:18 -0500 | [diff] [blame] | 228 | for (unsigned p = 1; p < fMetadata.fProxyCount; ++p) { |
Greg Daniel | 549325c | 2019-10-30 16:19:20 -0400 | [diff] [blame] | 229 | fViewCountPairs[p].~ViewCountPair(); |
Brian Salomon | 336ce7b | 2017-09-08 08:23:58 -0400 | [diff] [blame] | 230 | } |
| 231 | } |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 232 | |
| 233 | const char* name() const override { return "TextureOp"; } |
| 234 | |
Chris Dalton | 1706cbf | 2019-05-21 19:35:29 -0600 | [diff] [blame] | 235 | void visitProxies(const VisitProxyFunc& func) const override { |
Michael Ludwig | adb12e7 | 2019-12-04 16:19:18 -0500 | [diff] [blame] | 236 | bool mipped = (GrSamplerState::Filter::kMipMap == fMetadata.filter()); |
| 237 | for (unsigned p = 0; p < fMetadata.fProxyCount; ++p) { |
| 238 | func(fViewCountPairs[p].fProxy.get(), GrMipMapped(mipped)); |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 239 | } |
Chris Dalton | dbb833b | 2020-03-17 12:15:46 -0600 | [diff] [blame] | 240 | if (fDesc && fDesc->fProgramInfo) { |
| 241 | fDesc->fProgramInfo->visitFPProxies(func); |
| 242 | } |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 243 | } |
Robert Phillips | b493eeb | 2017-09-13 13:10:52 -0400 | [diff] [blame] | 244 | |
Brian Osman | 9a390ac | 2018-11-12 09:47:48 -0500 | [diff] [blame] | 245 | #ifdef SK_DEBUG |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 246 | SkString dumpInfo() const override { |
| 247 | SkString str; |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 248 | str.appendf("# draws: %d\n", fQuads.count()); |
Michael Ludwig | 425eb45 | 2019-06-27 10:13:27 -0400 | [diff] [blame] | 249 | auto iter = fQuads.iterator(); |
Michael Ludwig | adb12e7 | 2019-12-04 16:19:18 -0500 | [diff] [blame] | 250 | for (unsigned p = 0; p < fMetadata.fProxyCount; ++p) { |
Robert Phillips | 32803ff | 2019-10-23 08:26:08 -0400 | [diff] [blame] | 251 | str.appendf("Proxy ID: %d, Filter: %d\n", |
Michael Ludwig | adb12e7 | 2019-12-04 16:19:18 -0500 | [diff] [blame] | 252 | fViewCountPairs[p].fProxy->uniqueID().asUInt(), |
| 253 | static_cast<int>(fMetadata.fFilter)); |
Michael Ludwig | 425eb45 | 2019-06-27 10:13:27 -0400 | [diff] [blame] | 254 | int i = 0; |
Greg Daniel | 549325c | 2019-10-30 16:19:20 -0400 | [diff] [blame] | 255 | while(i < fViewCountPairs[p].fQuadCnt && iter.next()) { |
Michael Ludwig | 704d540 | 2019-11-25 09:43:37 -0500 | [diff] [blame] | 256 | const GrQuad* quad = iter.deviceQuad(); |
| 257 | GrQuad uv = iter.isLocalValid() ? *(iter.localQuad()) : GrQuad(); |
Brian Salomon | 2432d06 | 2020-04-16 20:48:09 -0400 | [diff] [blame^] | 258 | const ColorSubsetAndAA& info = iter.metadata(); |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 259 | str.appendf( |
Brian Salomon | 2432d06 | 2020-04-16 20:48:09 -0400 | [diff] [blame^] | 260 | "%d: Color: 0x%08x, Subset(%d): [L: %.2f, T: %.2f, R: %.2f, B: %.2f]\n" |
Michael Ludwig | f339dfe | 2019-06-27 10:41:28 -0400 | [diff] [blame] | 261 | " UVs [(%.2f, %.2f), (%.2f, %.2f), (%.2f, %.2f), (%.2f, %.2f)]\n" |
| 262 | " Quad [(%.2f, %.2f), (%.2f, %.2f), (%.2f, %.2f), (%.2f, %.2f)]\n", |
Brian Salomon | 2432d06 | 2020-04-16 20:48:09 -0400 | [diff] [blame^] | 263 | i, info.fColor.toBytes_RGBA(), fMetadata.fSubset, info.fSubsetRect.fLeft, |
| 264 | info.fSubsetRect.fTop, info.fSubsetRect.fRight, info.fSubsetRect.fBottom, |
Michael Ludwig | 704d540 | 2019-11-25 09:43:37 -0500 | [diff] [blame] | 265 | quad->point(0).fX, quad->point(0).fY, quad->point(1).fX, quad->point(1).fY, |
| 266 | quad->point(2).fX, quad->point(2).fY, quad->point(3).fX, quad->point(3).fY, |
Michael Ludwig | f339dfe | 2019-06-27 10:41:28 -0400 | [diff] [blame] | 267 | uv.point(0).fX, uv.point(0).fY, uv.point(1).fX, uv.point(1).fY, |
| 268 | uv.point(2).fX, uv.point(2).fY, uv.point(3).fX, uv.point(3).fY); |
| 269 | |
Michael Ludwig | 425eb45 | 2019-06-27 10:13:27 -0400 | [diff] [blame] | 270 | i++; |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 271 | } |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 272 | } |
| 273 | str += INHERITED::dumpInfo(); |
| 274 | return str; |
| 275 | } |
Michael Ludwig | 4ef1ca1 | 2019-12-19 10:58:52 -0500 | [diff] [blame] | 276 | |
| 277 | static void ValidateResourceLimits() { |
| 278 | // The op implementation has an upper bound on the number of quads that it can represent. |
| 279 | // However, the resource manager imposes its own limit on the number of quads, which should |
| 280 | // always be lower than the numerical limit this op can hold. |
| 281 | using CountStorage = decltype(Metadata::fTotalQuadCount); |
| 282 | CountStorage maxQuadCount = std::numeric_limits<CountStorage>::max(); |
| 283 | // GrResourceProvider::Max...() is typed as int, so don't compare across signed/unsigned. |
| 284 | int resourceLimit = SkTo<int>(maxQuadCount); |
| 285 | SkASSERT(GrResourceProvider::MaxNumAAQuads() <= resourceLimit && |
| 286 | GrResourceProvider::MaxNumNonAAQuads() <= resourceLimit); |
| 287 | } |
Brian Osman | 9a390ac | 2018-11-12 09:47:48 -0500 | [diff] [blame] | 288 | #endif |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 289 | |
Brian Osman | 5ced0bf | 2019-03-15 10:15:29 -0400 | [diff] [blame] | 290 | GrProcessorSet::Analysis finalize( |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 291 | const GrCaps& caps, const GrAppliedClip*, bool hasMixedSampledCoverage, |
| 292 | GrClampType clampType) override { |
Michael Ludwig | adb12e7 | 2019-12-04 16:19:18 -0500 | [diff] [blame] | 293 | SkASSERT(fMetadata.colorType() == ColorType::kNone); |
Michael Ludwig | 425eb45 | 2019-06-27 10:13:27 -0400 | [diff] [blame] | 294 | auto iter = fQuads.metadata(); |
| 295 | while(iter.next()) { |
Brian Osman | 2715bf5 | 2019-12-06 14:38:47 -0500 | [diff] [blame] | 296 | auto colorType = GrQuadPerEdgeAA::MinColorType(iter->fColor); |
Brian Osman | 788b916 | 2020-02-07 10:36:46 -0500 | [diff] [blame] | 297 | fMetadata.fColorType = std::max(fMetadata.fColorType, static_cast<uint16_t>(colorType)); |
Brian Osman | 8fa7ab4 | 2019-03-18 10:22:42 -0400 | [diff] [blame] | 298 | } |
Chris Dalton | 4b62aed | 2019-01-15 11:53:00 -0700 | [diff] [blame] | 299 | return GrProcessorSet::EmptySetAnalysis(); |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 300 | } |
| 301 | |
Brian Salomon | 485b8c6 | 2018-01-12 15:11:06 -0500 | [diff] [blame] | 302 | FixedFunctionFlags fixedFunctionFlags() const override { |
Michael Ludwig | adb12e7 | 2019-12-04 16:19:18 -0500 | [diff] [blame] | 303 | return fMetadata.aaType() == GrAAType::kMSAA ? FixedFunctionFlags::kUsesHWAA |
| 304 | : FixedFunctionFlags::kNone; |
Brian Salomon | 485b8c6 | 2018-01-12 15:11:06 -0500 | [diff] [blame] | 305 | } |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 306 | |
| 307 | DEFINE_OP_CLASS_ID |
| 308 | |
| 309 | private: |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 310 | friend class ::GrOpMemoryPool; |
Brian Salomon | 762d5e7 | 2017-12-01 10:25:08 -0500 | [diff] [blame] | 311 | |
Brian Salomon | 2432d06 | 2020-04-16 20:48:09 -0400 | [diff] [blame^] | 312 | struct ColorSubsetAndAA { |
| 313 | ColorSubsetAndAA(const SkPMColor4f& color, const SkRect& subsetRect, GrQuadAAFlags aaFlags) |
Michael Ludwig | 425eb45 | 2019-06-27 10:13:27 -0400 | [diff] [blame] | 314 | : fColor(color) |
Brian Salomon | 2432d06 | 2020-04-16 20:48:09 -0400 | [diff] [blame^] | 315 | , fSubsetRect(subsetRect) |
Michael Ludwig | 4384f04 | 2019-12-05 10:30:35 -0500 | [diff] [blame] | 316 | , fAAFlags(static_cast<uint16_t>(aaFlags)) { |
| 317 | SkASSERT(fAAFlags == static_cast<uint16_t>(aaFlags)); |
Michael Ludwig | 425eb45 | 2019-06-27 10:13:27 -0400 | [diff] [blame] | 318 | } |
Michael Ludwig | 425eb45 | 2019-06-27 10:13:27 -0400 | [diff] [blame] | 319 | |
| 320 | SkPMColor4f fColor; |
Brian Salomon | 2432d06 | 2020-04-16 20:48:09 -0400 | [diff] [blame^] | 321 | // If the op doesn't use subsets, this is ignored. If the op uses subsets and the specific |
Michael Ludwig | 119ac6d | 2019-11-21 09:26:46 -0500 | [diff] [blame] | 322 | // entry does not, this rect will equal kLargeRect, so it automatically has no effect. |
Brian Salomon | 2432d06 | 2020-04-16 20:48:09 -0400 | [diff] [blame^] | 323 | SkRect fSubsetRect; |
Michael Ludwig | 425eb45 | 2019-06-27 10:13:27 -0400 | [diff] [blame] | 324 | unsigned fAAFlags : 4; |
| 325 | |
Michael Ludwig | 425eb45 | 2019-06-27 10:13:27 -0400 | [diff] [blame] | 326 | GrQuadAAFlags aaFlags() const { return static_cast<GrQuadAAFlags>(fAAFlags); } |
| 327 | }; |
Michael Ludwig | adb12e7 | 2019-12-04 16:19:18 -0500 | [diff] [blame] | 328 | |
Greg Daniel | 549325c | 2019-10-30 16:19:20 -0400 | [diff] [blame] | 329 | struct ViewCountPair { |
Michael Ludwig | adb12e7 | 2019-12-04 16:19:18 -0500 | [diff] [blame] | 330 | // Normally this would be a GrSurfaceProxyView, but GrTextureOp applies the GrOrigin right |
| 331 | // away so it doesn't need to be stored, and all ViewCountPairs in an op have the same |
| 332 | // swizzle so that is stored in the op metadata. |
| 333 | sk_sp<GrSurfaceProxy> fProxy; |
Michael Ludwig | 425eb45 | 2019-06-27 10:13:27 -0400 | [diff] [blame] | 334 | int fQuadCnt; |
| 335 | }; |
| 336 | |
Michael Ludwig | adb12e7 | 2019-12-04 16:19:18 -0500 | [diff] [blame] | 337 | // TextureOp and ViewCountPair are 8 byte aligned. This is packed into 8 bytes to minimally |
| 338 | // increase the size of the op; increasing the op size can have a surprising impact on |
| 339 | // performance (since texture ops are one of the most commonly used in an app). |
| 340 | struct Metadata { |
| 341 | // AAType must be filled after initialization; ColorType is determined in finalize() |
| 342 | Metadata(const GrSwizzle& swizzle, GrSamplerState::Filter filter, |
Brian Salomon | 2432d06 | 2020-04-16 20:48:09 -0400 | [diff] [blame^] | 343 | GrQuadPerEdgeAA::Subset subset, GrTextureOp::Saturate saturate) |
Michael Ludwig | adb12e7 | 2019-12-04 16:19:18 -0500 | [diff] [blame] | 344 | : fSwizzle(swizzle) |
| 345 | , fProxyCount(1) |
| 346 | , fTotalQuadCount(1) |
Michael Ludwig | 4384f04 | 2019-12-05 10:30:35 -0500 | [diff] [blame] | 347 | , fFilter(static_cast<uint16_t>(filter)) |
| 348 | , fAAType(static_cast<uint16_t>(GrAAType::kNone)) |
| 349 | , fColorType(static_cast<uint16_t>(ColorType::kNone)) |
Brian Salomon | 2432d06 | 2020-04-16 20:48:09 -0400 | [diff] [blame^] | 350 | , fSubset(static_cast<uint16_t>(subset)) |
Michael Ludwig | 4384f04 | 2019-12-05 10:30:35 -0500 | [diff] [blame] | 351 | , fSaturate(static_cast<uint16_t>(saturate)) {} |
Michael Ludwig | adb12e7 | 2019-12-04 16:19:18 -0500 | [diff] [blame] | 352 | |
Michael Ludwig | 4384f04 | 2019-12-05 10:30:35 -0500 | [diff] [blame] | 353 | GrSwizzle fSwizzle; // sizeof(GrSwizzle) == uint16_t |
Michael Ludwig | adb12e7 | 2019-12-04 16:19:18 -0500 | [diff] [blame] | 354 | uint16_t fProxyCount; |
| 355 | // This will be >= fProxyCount, since a proxy may be drawn multiple times |
| 356 | uint16_t fTotalQuadCount; |
| 357 | |
Michael Ludwig | 4384f04 | 2019-12-05 10:30:35 -0500 | [diff] [blame] | 358 | // These must be based on uint16_t to help MSVC's pack bitfields optimally |
| 359 | uint16_t fFilter : 2; // GrSamplerState::Filter |
| 360 | uint16_t fAAType : 2; // GrAAType |
| 361 | uint16_t fColorType : 2; // GrQuadPerEdgeAA::ColorType |
Brian Salomon | 2432d06 | 2020-04-16 20:48:09 -0400 | [diff] [blame^] | 362 | uint16_t fSubset : 1; // bool |
Michael Ludwig | 4384f04 | 2019-12-05 10:30:35 -0500 | [diff] [blame] | 363 | uint16_t fSaturate : 1; // bool |
| 364 | uint16_t fUnused : 8; // # of bits left before Metadata exceeds 8 bytes |
Michael Ludwig | adb12e7 | 2019-12-04 16:19:18 -0500 | [diff] [blame] | 365 | |
| 366 | GrSamplerState::Filter filter() const { |
| 367 | return static_cast<GrSamplerState::Filter>(fFilter); |
| 368 | } |
| 369 | GrAAType aaType() const { return static_cast<GrAAType>(fAAType); } |
| 370 | ColorType colorType() const { return static_cast<ColorType>(fColorType); } |
Brian Salomon | 2432d06 | 2020-04-16 20:48:09 -0400 | [diff] [blame^] | 371 | Subset subset() const { return static_cast<Subset>(fSubset); } |
Michael Ludwig | adb12e7 | 2019-12-04 16:19:18 -0500 | [diff] [blame] | 372 | GrTextureOp::Saturate saturate() const { |
| 373 | return static_cast<GrTextureOp::Saturate>(fSaturate); |
| 374 | } |
| 375 | |
| 376 | static_assert(GrSamplerState::kFilterCount <= 4); |
| 377 | static_assert(kGrAATypeCount <= 4); |
| 378 | static_assert(GrQuadPerEdgeAA::kColorTypeCount <= 4); |
| 379 | }; |
Michael Ludwig | 4384f04 | 2019-12-05 10:30:35 -0500 | [diff] [blame] | 380 | static_assert(sizeof(Metadata) == 8); |
Michael Ludwig | adb12e7 | 2019-12-04 16:19:18 -0500 | [diff] [blame] | 381 | |
Chris Dalton | dbb833b | 2020-03-17 12:15:46 -0600 | [diff] [blame] | 382 | // This descriptor is used to store the draw info we decide on during on(Pre)PrepareDraws. We |
| 383 | // store the data in a separate struct in order to minimize the size of the TextureOp. |
| 384 | // Historically, increasing the TextureOp's size has caused surprising perf regressions, but we |
| 385 | // may want to re-evaluate whether this is still necessary. |
Robert Phillips | c5a2c75 | 2019-10-24 13:11:45 -0400 | [diff] [blame] | 386 | // |
Chris Dalton | dbb833b | 2020-03-17 12:15:46 -0600 | [diff] [blame] | 387 | // In the onPrePrepareDraws case it is allocated in the creation-time opData arena, and |
| 388 | // allocatePrePreparedVertices is also called. |
Robert Phillips | c5a2c75 | 2019-10-24 13:11:45 -0400 | [diff] [blame] | 389 | // |
Chris Dalton | dbb833b | 2020-03-17 12:15:46 -0600 | [diff] [blame] | 390 | // In the onPrepareDraws case this descriptor is allocated in the flush-time arena (i.e., as |
| 391 | // part of the flushState). |
| 392 | struct Desc { |
| 393 | VertexSpec fVertexSpec; |
| 394 | int fNumProxies = 0; |
| 395 | int fNumTotalQuads = 0; |
Robert Phillips | 32803ff | 2019-10-23 08:26:08 -0400 | [diff] [blame] | 396 | |
Chris Dalton | dbb833b | 2020-03-17 12:15:46 -0600 | [diff] [blame] | 397 | // This member variable is only used by 'onPrePrepareDraws'. |
| 398 | char* fPrePreparedVertices = nullptr; |
| 399 | |
| 400 | GrProgramInfo* fProgramInfo = nullptr; |
| 401 | |
| 402 | sk_sp<const GrBuffer> fIndexBuffer; |
| 403 | sk_sp<const GrBuffer> fVertexBuffer; |
| 404 | int fBaseVertex; |
Robert Phillips | c5a2c75 | 2019-10-24 13:11:45 -0400 | [diff] [blame] | 405 | |
| 406 | // How big should 'fVertices' be to hold all the vertex data? |
| 407 | size_t totalSizeInBytes() const { |
Chris Dalton | dbb833b | 2020-03-17 12:15:46 -0600 | [diff] [blame] | 408 | return this->totalNumVertices() * fVertexSpec.vertexSize(); |
Robert Phillips | c5a2c75 | 2019-10-24 13:11:45 -0400 | [diff] [blame] | 409 | } |
| 410 | |
Robert Phillips | c5a2c75 | 2019-10-24 13:11:45 -0400 | [diff] [blame] | 411 | int totalNumVertices() const { |
| 412 | return fNumTotalQuads * fVertexSpec.verticesPerQuad(); |
| 413 | } |
Robert Phillips | c5a2c75 | 2019-10-24 13:11:45 -0400 | [diff] [blame] | 414 | |
Chris Dalton | dbb833b | 2020-03-17 12:15:46 -0600 | [diff] [blame] | 415 | void allocatePrePreparedVertices(SkArenaAlloc* arena) { |
| 416 | fPrePreparedVertices = arena->makeArrayDefault<char>(this->totalSizeInBytes()); |
Robert Phillips | c5a2c75 | 2019-10-24 13:11:45 -0400 | [diff] [blame] | 417 | } |
| 418 | |
Robert Phillips | 32803ff | 2019-10-23 08:26:08 -0400 | [diff] [blame] | 419 | }; |
| 420 | |
Brian Salomon | 2432d06 | 2020-04-16 20:48:09 -0400 | [diff] [blame^] | 421 | // If subsetRect is not null it will be used to apply a strict src rect-style constraint. |
Greg Daniel | 549325c | 2019-10-30 16:19:20 -0400 | [diff] [blame] | 422 | TextureOp(GrSurfaceProxyView proxyView, |
Brian Salomon | f19f9ca | 2019-09-18 15:54:26 -0400 | [diff] [blame] | 423 | sk_sp<GrColorSpaceXform> textureColorSpaceXform, |
| 424 | GrSamplerState::Filter filter, |
| 425 | const SkPMColor4f& color, |
| 426 | GrTextureOp::Saturate saturate, |
| 427 | GrAAType aaType, |
Michael Ludwig | 6b45c5d | 2020-02-07 09:56:38 -0500 | [diff] [blame] | 428 | DrawQuad* quad, |
Brian Salomon | 2432d06 | 2020-04-16 20:48:09 -0400 | [diff] [blame^] | 429 | const SkRect* subsetRect) |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 430 | : INHERITED(ClassID()) |
Michael Ludwig | f339dfe | 2019-06-27 10:41:28 -0400 | [diff] [blame] | 431 | , fQuads(1, true /* includes locals */) |
Brian Osman | 3ebd354 | 2018-07-30 14:36:53 -0400 | [diff] [blame] | 432 | , fTextureColorSpaceXform(std::move(textureColorSpaceXform)) |
Chris Dalton | dbb833b | 2020-03-17 12:15:46 -0600 | [diff] [blame] | 433 | , fDesc(nullptr) |
Brian Salomon | 2432d06 | 2020-04-16 20:48:09 -0400 | [diff] [blame^] | 434 | , fMetadata(proxyView.swizzle(), filter, Subset(!!subsetRect), saturate) { |
Michael Ludwig | adb12e7 | 2019-12-04 16:19:18 -0500 | [diff] [blame] | 435 | |
Michael Ludwig | 6bee776 | 2018-10-19 09:50:36 -0400 | [diff] [blame] | 436 | // Clean up disparities between the overall aa type and edge configuration and apply |
| 437 | // optimizations based on the rect and matrix when appropriate |
Michael Ludwig | 6b45c5d | 2020-02-07 09:56:38 -0500 | [diff] [blame] | 438 | GrQuadUtils::ResolveAAType(aaType, quad->fEdgeFlags, quad->fDevice, |
| 439 | &aaType, &quad->fEdgeFlags); |
Michael Ludwig | 4384f04 | 2019-12-05 10:30:35 -0500 | [diff] [blame] | 440 | fMetadata.fAAType = static_cast<uint16_t>(aaType); |
Michael Ludwig | 6bee776 | 2018-10-19 09:50:36 -0400 | [diff] [blame] | 441 | |
Brian Salomon | f170904 | 2018-10-03 11:57:00 -0400 | [diff] [blame] | 442 | // We expect our caller to have already caught this optimization. |
Brian Salomon | 2432d06 | 2020-04-16 20:48:09 -0400 | [diff] [blame^] | 443 | SkASSERT(!subsetRect || |
| 444 | !subsetRect->contains(proxyView.proxy()->backingStoreBoundsRect())); |
Michael Ludwig | 009b92e | 2019-02-15 16:03:53 -0500 | [diff] [blame] | 445 | |
Brian Salomon | f09abc5 | 2018-10-03 15:59:04 -0400 | [diff] [blame] | 446 | // We may have had a strict constraint with nearest filter solely due to possible AA bloat. |
| 447 | // If we don't have (or determined we don't need) coverage AA then we can skip using a |
Brian Salomon | 2432d06 | 2020-04-16 20:48:09 -0400 | [diff] [blame^] | 448 | // subset. |
| 449 | if (subsetRect && filter == GrSamplerState::Filter::kNearest && |
Michael Ludwig | 6bee776 | 2018-10-19 09:50:36 -0400 | [diff] [blame] | 450 | aaType != GrAAType::kCoverage) { |
Brian Salomon | 2432d06 | 2020-04-16 20:48:09 -0400 | [diff] [blame^] | 451 | subsetRect = nullptr; |
| 452 | fMetadata.fSubset = static_cast<uint16_t>(Subset::kNo); |
Brian Salomon | f09abc5 | 2018-10-03 15:59:04 -0400 | [diff] [blame] | 453 | } |
Michael Ludwig | c96fc37 | 2019-01-08 15:46:15 -0500 | [diff] [blame] | 454 | |
Brian Salomon | 2432d06 | 2020-04-16 20:48:09 -0400 | [diff] [blame^] | 455 | // Normalize src coordinates and the subset (if set) |
Michael Ludwig | adb12e7 | 2019-12-04 16:19:18 -0500 | [diff] [blame] | 456 | NormalizationParams params = proxy_normalization_params(proxyView.proxy(), |
| 457 | proxyView.origin()); |
Michael Ludwig | 6b45c5d | 2020-02-07 09:56:38 -0500 | [diff] [blame] | 458 | normalize_src_quad(params, &quad->fLocal); |
Brian Salomon | 2432d06 | 2020-04-16 20:48:09 -0400 | [diff] [blame^] | 459 | SkRect subset = normalize_subset(filter, params, subsetRect); |
Michael Ludwig | 119ac6d | 2019-11-21 09:26:46 -0500 | [diff] [blame] | 460 | |
Michael Ludwig | 949ceb2 | 2020-02-07 10:14:45 -0500 | [diff] [blame] | 461 | // Set bounds before clipping so we don't have to worry about unioning the bounds of |
| 462 | // the two potential quads (GrQuad::bounds() is perspective-safe). |
Michael Ludwig | 6b45c5d | 2020-02-07 09:56:38 -0500 | [diff] [blame] | 463 | this->setBounds(quad->fDevice.bounds(), HasAABloat(aaType == GrAAType::kCoverage), |
Greg Daniel | 5faf474 | 2019-10-01 15:14:44 -0400 | [diff] [blame] | 464 | IsHairline::kNo); |
Michael Ludwig | 949ceb2 | 2020-02-07 10:14:45 -0500 | [diff] [blame] | 465 | |
Brian Salomon | 2432d06 | 2020-04-16 20:48:09 -0400 | [diff] [blame^] | 466 | int quadCount = this->appendQuad(quad, color, subset); |
Michael Ludwig | 949ceb2 | 2020-02-07 10:14:45 -0500 | [diff] [blame] | 467 | fViewCountPairs[0] = {proxyView.detachProxy(), quadCount}; |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 468 | } |
Robert Phillips | bbd459d | 2019-10-29 14:40:03 -0400 | [diff] [blame] | 469 | |
Michael Ludwig | adb12e7 | 2019-12-04 16:19:18 -0500 | [diff] [blame] | 470 | TextureOp(GrRenderTargetContext::TextureSetEntry set[], |
Brian Salomon | f19f9ca | 2019-09-18 15:54:26 -0400 | [diff] [blame] | 471 | int cnt, |
Michael Ludwig | 379e496 | 2019-12-06 13:21:26 -0500 | [diff] [blame] | 472 | int proxyRunCnt, |
Brian Salomon | f19f9ca | 2019-09-18 15:54:26 -0400 | [diff] [blame] | 473 | GrSamplerState::Filter filter, |
| 474 | GrTextureOp::Saturate saturate, |
| 475 | GrAAType aaType, |
| 476 | SkCanvas::SrcRectConstraint constraint, |
| 477 | const SkMatrix& viewMatrix, |
Brian Salomon | d003d22 | 2018-11-26 13:25:05 -0500 | [diff] [blame] | 478 | sk_sp<GrColorSpaceXform> textureColorSpaceXform) |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 479 | : INHERITED(ClassID()) |
Michael Ludwig | f339dfe | 2019-06-27 10:41:28 -0400 | [diff] [blame] | 480 | , fQuads(cnt, true /* includes locals */) |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 481 | , fTextureColorSpaceXform(std::move(textureColorSpaceXform)) |
Chris Dalton | dbb833b | 2020-03-17 12:15:46 -0600 | [diff] [blame] | 482 | , fDesc(nullptr) |
Michael Ludwig | adb12e7 | 2019-12-04 16:19:18 -0500 | [diff] [blame] | 483 | , fMetadata(set[0].fProxyView.swizzle(), GrSamplerState::Filter::kNearest, |
Brian Salomon | 2432d06 | 2020-04-16 20:48:09 -0400 | [diff] [blame^] | 484 | Subset::kNo, saturate) { |
Michael Ludwig | adb12e7 | 2019-12-04 16:19:18 -0500 | [diff] [blame] | 485 | // Update counts to reflect the batch op |
Michael Ludwig | 379e496 | 2019-12-06 13:21:26 -0500 | [diff] [blame] | 486 | fMetadata.fProxyCount = SkToUInt(proxyRunCnt); |
Michael Ludwig | adb12e7 | 2019-12-04 16:19:18 -0500 | [diff] [blame] | 487 | fMetadata.fTotalQuadCount = SkToUInt(cnt); |
| 488 | |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 489 | SkRect bounds = SkRectPriv::MakeLargestInverted(); |
Michael Ludwig | 119ac6d | 2019-11-21 09:26:46 -0500 | [diff] [blame] | 490 | |
| 491 | GrAAType netAAType = GrAAType::kNone; // aa type maximally compatible with all dst rects |
Brian Salomon | 2432d06 | 2020-04-16 20:48:09 -0400 | [diff] [blame^] | 492 | Subset netSubset = Subset::kNo; |
Michael Ludwig | 119ac6d | 2019-11-21 09:26:46 -0500 | [diff] [blame] | 493 | GrSamplerState::Filter netFilter = GrSamplerState::Filter::kNearest; |
| 494 | |
Michael Ludwig | 379e496 | 2019-12-06 13:21:26 -0500 | [diff] [blame] | 495 | const GrSurfaceProxy* curProxy = nullptr; |
Michael Ludwig | 949ceb2 | 2020-02-07 10:14:45 -0500 | [diff] [blame] | 496 | |
Michael Ludwig | 379e496 | 2019-12-06 13:21:26 -0500 | [diff] [blame] | 497 | // 'q' is the index in 'set' and fQuadBuffer; 'p' is the index in fViewCountPairs and only |
| 498 | // increases when set[q]'s proxy changes. |
Michael Ludwig | 949ceb2 | 2020-02-07 10:14:45 -0500 | [diff] [blame] | 499 | int p = 0; |
| 500 | for (int q = 0; q < cnt; ++q) { |
Michael Ludwig | 379e496 | 2019-12-06 13:21:26 -0500 | [diff] [blame] | 501 | if (q == 0) { |
Greg Daniel | 549325c | 2019-10-30 16:19:20 -0400 | [diff] [blame] | 502 | // We do not placement new the first ViewCountPair since that one is allocated and |
| 503 | // initialized as part of the GrTextureOp creation. |
Michael Ludwig | 379e496 | 2019-12-06 13:21:26 -0500 | [diff] [blame] | 504 | fViewCountPairs[0].fProxy = set[0].fProxyView.detachProxy(); |
| 505 | fViewCountPairs[0].fQuadCnt = 0; |
| 506 | curProxy = fViewCountPairs[0].fProxy.get(); |
| 507 | } else if (set[q].fProxyView.proxy() != curProxy) { |
Greg Daniel | 549325c | 2019-10-30 16:19:20 -0400 | [diff] [blame] | 508 | // We must placement new the ViewCountPairs here so that the sk_sps in the |
| 509 | // GrSurfaceProxyView get initialized properly. |
Michael Ludwig | 379e496 | 2019-12-06 13:21:26 -0500 | [diff] [blame] | 510 | new(&fViewCountPairs[++p])ViewCountPair({set[q].fProxyView.detachProxy(), 0}); |
Michael Ludwig | adb12e7 | 2019-12-04 16:19:18 -0500 | [diff] [blame] | 511 | |
Michael Ludwig | 379e496 | 2019-12-06 13:21:26 -0500 | [diff] [blame] | 512 | curProxy = fViewCountPairs[p].fProxy.get(); |
Greg Daniel | c71c796 | 2020-01-14 16:44:18 -0500 | [diff] [blame] | 513 | SkASSERT(GrTextureProxy::ProxiesAreCompatibleAsDynamicState( |
| 514 | curProxy, fViewCountPairs[0].fProxy.get())); |
Michael Ludwig | 379e496 | 2019-12-06 13:21:26 -0500 | [diff] [blame] | 515 | SkASSERT(fMetadata.fSwizzle == set[q].fProxyView.swizzle()); |
Michael Ludwig | 379e496 | 2019-12-06 13:21:26 -0500 | [diff] [blame] | 516 | } // else another quad referencing the same proxy |
Michael Ludwig | ce62dec | 2019-02-19 11:48:46 -0500 | [diff] [blame] | 517 | |
Michael Ludwig | 7ae2ab5 | 2019-03-05 16:00:20 -0500 | [diff] [blame] | 518 | SkMatrix ctm = viewMatrix; |
Michael Ludwig | 379e496 | 2019-12-06 13:21:26 -0500 | [diff] [blame] | 519 | if (set[q].fPreViewMatrix) { |
| 520 | ctm.preConcat(*set[q].fPreViewMatrix); |
Michael Ludwig | 7ae2ab5 | 2019-03-05 16:00:20 -0500 | [diff] [blame] | 521 | } |
| 522 | |
Michael Ludwig | f339dfe | 2019-06-27 10:41:28 -0400 | [diff] [blame] | 523 | // Use dstRect/srcRect unless dstClip is provided, in which case derive new source |
| 524 | // coordinates by mapping dstClipQuad by the dstRect to srcRect transform. |
Michael Ludwig | 6b45c5d | 2020-02-07 09:56:38 -0500 | [diff] [blame] | 525 | DrawQuad quad; |
Michael Ludwig | 379e496 | 2019-12-06 13:21:26 -0500 | [diff] [blame] | 526 | if (set[q].fDstClipQuad) { |
Michael Ludwig | 6b45c5d | 2020-02-07 09:56:38 -0500 | [diff] [blame] | 527 | quad.fDevice = GrQuad::MakeFromSkQuad(set[q].fDstClipQuad, ctm); |
Michael Ludwig | f339dfe | 2019-06-27 10:41:28 -0400 | [diff] [blame] | 528 | |
| 529 | SkPoint srcPts[4]; |
Michael Ludwig | 379e496 | 2019-12-06 13:21:26 -0500 | [diff] [blame] | 530 | GrMapRectPoints(set[q].fDstRect, set[q].fSrcRect, set[q].fDstClipQuad, srcPts, 4); |
Michael Ludwig | 6b45c5d | 2020-02-07 09:56:38 -0500 | [diff] [blame] | 531 | quad.fLocal = GrQuad::MakeFromSkQuad(srcPts, SkMatrix::I()); |
Michael Ludwig | f339dfe | 2019-06-27 10:41:28 -0400 | [diff] [blame] | 532 | } else { |
Michael Ludwig | 6b45c5d | 2020-02-07 09:56:38 -0500 | [diff] [blame] | 533 | quad.fDevice = GrQuad::MakeFromRect(set[q].fDstRect, ctm); |
| 534 | quad.fLocal = GrQuad(set[q].fSrcRect); |
Michael Ludwig | f339dfe | 2019-06-27 10:41:28 -0400 | [diff] [blame] | 535 | } |
Michael Ludwig | ce62dec | 2019-02-19 11:48:46 -0500 | [diff] [blame] | 536 | |
Michael Ludwig | 6b45c5d | 2020-02-07 09:56:38 -0500 | [diff] [blame] | 537 | if (netFilter != filter && filter_has_effect(quad.fLocal, quad.fDevice)) { |
Michael Ludwig | 119ac6d | 2019-11-21 09:26:46 -0500 | [diff] [blame] | 538 | // The only way netFilter != filter is if bilerp is requested and we haven't yet |
| 539 | // found a quad that requires bilerp (so net is still nearest). |
| 540 | SkASSERT(netFilter == GrSamplerState::Filter::kNearest && |
| 541 | filter == GrSamplerState::Filter::kBilerp); |
| 542 | netFilter = GrSamplerState::Filter::kBilerp; |
Michael Ludwig | 22429f9 | 2019-06-27 10:44:48 -0400 | [diff] [blame] | 543 | } |
| 544 | |
Michael Ludwig | 119ac6d | 2019-11-21 09:26:46 -0500 | [diff] [blame] | 545 | // Normalize the src quads and apply origin |
Michael Ludwig | adb12e7 | 2019-12-04 16:19:18 -0500 | [diff] [blame] | 546 | NormalizationParams proxyParams = proxy_normalization_params( |
Michael Ludwig | 379e496 | 2019-12-06 13:21:26 -0500 | [diff] [blame] | 547 | curProxy, set[q].fProxyView.origin()); |
Michael Ludwig | 6b45c5d | 2020-02-07 09:56:38 -0500 | [diff] [blame] | 548 | normalize_src_quad(proxyParams, &quad.fLocal); |
Michael Ludwig | 119ac6d | 2019-11-21 09:26:46 -0500 | [diff] [blame] | 549 | |
| 550 | // Update overall bounds of the op as the union of all quads |
Michael Ludwig | 6b45c5d | 2020-02-07 09:56:38 -0500 | [diff] [blame] | 551 | bounds.joinPossiblyEmptyRect(quad.fDevice.bounds()); |
Michael Ludwig | 119ac6d | 2019-11-21 09:26:46 -0500 | [diff] [blame] | 552 | |
| 553 | // Determine the AA type for the quad, then merge with net AA type |
Michael Ludwig | 6bee776 | 2018-10-19 09:50:36 -0400 | [diff] [blame] | 554 | GrAAType aaForQuad; |
Michael Ludwig | 6b45c5d | 2020-02-07 09:56:38 -0500 | [diff] [blame] | 555 | GrQuadUtils::ResolveAAType(aaType, set[q].fAAFlags, quad.fDevice, |
| 556 | &aaForQuad, &quad.fEdgeFlags); |
Michael Ludwig | 6bee776 | 2018-10-19 09:50:36 -0400 | [diff] [blame] | 557 | // Resolve sets aaForQuad to aaType or None, there is never a change between aa methods |
| 558 | SkASSERT(aaForQuad == GrAAType::kNone || aaForQuad == aaType); |
Michael Ludwig | 119ac6d | 2019-11-21 09:26:46 -0500 | [diff] [blame] | 559 | if (netAAType == GrAAType::kNone && aaForQuad != GrAAType::kNone) { |
| 560 | netAAType = aaType; |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 561 | } |
Michael Ludwig | f339dfe | 2019-06-27 10:41:28 -0400 | [diff] [blame] | 562 | |
| 563 | // Calculate metadata for the entry |
Brian Salomon | 2432d06 | 2020-04-16 20:48:09 -0400 | [diff] [blame^] | 564 | const SkRect* subsetForQuad = nullptr; |
Michael Ludwig | 31ba718 | 2019-04-03 10:38:06 -0400 | [diff] [blame] | 565 | if (constraint == SkCanvas::kStrict_SrcRectConstraint) { |
| 566 | // Check (briefly) if the strict constraint is needed for this set entry |
Michael Ludwig | 379e496 | 2019-12-06 13:21:26 -0500 | [diff] [blame] | 567 | if (!set[q].fSrcRect.contains(curProxy->backingStoreBoundsRect()) && |
Michael Ludwig | 949ceb2 | 2020-02-07 10:14:45 -0500 | [diff] [blame] | 568 | (filter == GrSamplerState::Filter::kBilerp || |
Michael Ludwig | 119ac6d | 2019-11-21 09:26:46 -0500 | [diff] [blame] | 569 | aaForQuad == GrAAType::kCoverage)) { |
Michael Ludwig | 31ba718 | 2019-04-03 10:38:06 -0400 | [diff] [blame] | 570 | // Can't rely on hardware clamping and the draw will access outer texels |
Michael Ludwig | 119ac6d | 2019-11-21 09:26:46 -0500 | [diff] [blame] | 571 | // for AA and/or bilerp. Unlike filter quality, this op still has per-quad |
| 572 | // control over AA so that can check aaForQuad, not netAAType. |
Brian Salomon | 2432d06 | 2020-04-16 20:48:09 -0400 | [diff] [blame^] | 573 | netSubset = Subset::kYes; |
| 574 | subsetForQuad = &set[q].fSrcRect; |
Michael Ludwig | 31ba718 | 2019-04-03 10:38:06 -0400 | [diff] [blame] | 575 | } |
| 576 | } |
Brian Salomon | 2432d06 | 2020-04-16 20:48:09 -0400 | [diff] [blame^] | 577 | // This subset may represent a no-op, otherwise it will have the origin and dimensions |
Michael Ludwig | 7c6a4a8 | 2020-02-07 10:14:26 -0500 | [diff] [blame] | 578 | // of the texture applied to it. Insetting for bilinear filtering is deferred until |
| 579 | // on[Pre]Prepare so that the overall filter can be lazily determined. |
Brian Salomon | 2432d06 | 2020-04-16 20:48:09 -0400 | [diff] [blame^] | 580 | SkRect subset = normalize_subset(filter, proxyParams, subsetForQuad); |
Michael Ludwig | 119ac6d | 2019-11-21 09:26:46 -0500 | [diff] [blame] | 581 | |
Michael Ludwig | 949ceb2 | 2020-02-07 10:14:45 -0500 | [diff] [blame] | 582 | // Always append a quad (or 2 if perspective clipped), it just may refer back to a prior |
| 583 | // ViewCountPair (this frequently happens when Chrome draws 9-patches). |
Michael Ludwig | 379e496 | 2019-12-06 13:21:26 -0500 | [diff] [blame] | 584 | float alpha = SkTPin(set[q].fAlpha, 0.f, 1.f); |
Michael Ludwig | 949ceb2 | 2020-02-07 10:14:45 -0500 | [diff] [blame] | 585 | fViewCountPairs[p].fQuadCnt += this->appendQuad( |
Brian Salomon | 2432d06 | 2020-04-16 20:48:09 -0400 | [diff] [blame^] | 586 | &quad, {alpha, alpha, alpha, alpha}, subset); |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 587 | } |
Michael Ludwig | 406172a | 2019-12-06 14:05:19 -0500 | [diff] [blame] | 588 | // The # of proxy switches should match what was provided (+1 because we incremented p |
Michael Ludwig | 379e496 | 2019-12-06 13:21:26 -0500 | [diff] [blame] | 589 | // when a new proxy was encountered). |
Michael Ludwig | 406172a | 2019-12-06 14:05:19 -0500 | [diff] [blame] | 590 | SkASSERT((p + 1) == fMetadata.fProxyCount); |
Michael Ludwig | 379e496 | 2019-12-06 13:21:26 -0500 | [diff] [blame] | 591 | SkASSERT(fQuads.count() == fMetadata.fTotalQuadCount); |
Michael Ludwig | 119ac6d | 2019-11-21 09:26:46 -0500 | [diff] [blame] | 592 | |
Michael Ludwig | 4384f04 | 2019-12-05 10:30:35 -0500 | [diff] [blame] | 593 | fMetadata.fAAType = static_cast<uint16_t>(netAAType); |
| 594 | fMetadata.fFilter = static_cast<uint16_t>(netFilter); |
Brian Salomon | 2432d06 | 2020-04-16 20:48:09 -0400 | [diff] [blame^] | 595 | fMetadata.fSubset = static_cast<uint16_t>(netSubset); |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 596 | |
Michael Ludwig | 119ac6d | 2019-11-21 09:26:46 -0500 | [diff] [blame] | 597 | this->setBounds(bounds, HasAABloat(netAAType == GrAAType::kCoverage), IsHairline::kNo); |
Brian Salomon | 17031a7 | 2018-05-22 14:14:07 -0400 | [diff] [blame] | 598 | } |
| 599 | |
Brian Salomon | 2432d06 | 2020-04-16 20:48:09 -0400 | [diff] [blame^] | 600 | int appendQuad(DrawQuad* quad, const SkPMColor4f& color, const SkRect& subset) { |
Michael Ludwig | 949ceb2 | 2020-02-07 10:14:45 -0500 | [diff] [blame] | 601 | DrawQuad extra; |
Michael Ludwig | 465864c | 2020-02-10 09:30:04 -0500 | [diff] [blame] | 602 | // Only clip when there's anti-aliasing. When non-aa, the GPU clips just fine and there's |
| 603 | // no inset/outset math that requires w > 0. |
| 604 | int quadCount = quad->fEdgeFlags != GrQuadAAFlags::kNone ? |
| 605 | GrQuadUtils::ClipToW0(quad, &extra) : 1; |
Michael Ludwig | 949ceb2 | 2020-02-07 10:14:45 -0500 | [diff] [blame] | 606 | if (quadCount == 0) { |
| 607 | // We can't discard the op at this point, but disable AA flags so it won't go through |
| 608 | // inset/outset processing |
| 609 | quad->fEdgeFlags = GrQuadAAFlags::kNone; |
| 610 | quadCount = 1; |
| 611 | } |
Brian Salomon | 2432d06 | 2020-04-16 20:48:09 -0400 | [diff] [blame^] | 612 | fQuads.append(quad->fDevice, {color, subset, quad->fEdgeFlags}, &quad->fLocal); |
Michael Ludwig | 949ceb2 | 2020-02-07 10:14:45 -0500 | [diff] [blame] | 613 | if (quadCount > 1) { |
Brian Salomon | 2432d06 | 2020-04-16 20:48:09 -0400 | [diff] [blame^] | 614 | fQuads.append(extra.fDevice, {color, subset, extra.fEdgeFlags}, &extra.fLocal); |
Michael Ludwig | 949ceb2 | 2020-02-07 10:14:45 -0500 | [diff] [blame] | 615 | fMetadata.fTotalQuadCount++; |
| 616 | } |
| 617 | return quadCount; |
| 618 | } |
| 619 | |
Robert Phillips | 2669a7b | 2020-03-12 12:07:19 -0400 | [diff] [blame] | 620 | GrProgramInfo* programInfo() override { |
Chris Dalton | dbb833b | 2020-03-17 12:15:46 -0600 | [diff] [blame] | 621 | // Although this Op implements its own onPrePrepareDraws it calls GrMeshDrawOps' version so |
| 622 | // this entry point will be called. |
| 623 | return (fDesc) ? fDesc->fProgramInfo : nullptr; |
Robert Phillips | 2669a7b | 2020-03-12 12:07:19 -0400 | [diff] [blame] | 624 | } |
| 625 | |
Chris Dalton | dbb833b | 2020-03-17 12:15:46 -0600 | [diff] [blame] | 626 | void onCreateProgramInfo(const GrCaps* caps, |
| 627 | SkArenaAlloc* arena, |
Brian Salomon | 8afde5f | 2020-04-01 16:22:00 -0400 | [diff] [blame] | 628 | const GrSurfaceProxyView* writeView, |
Chris Dalton | dbb833b | 2020-03-17 12:15:46 -0600 | [diff] [blame] | 629 | GrAppliedClip&& appliedClip, |
| 630 | const GrXferProcessor::DstProxyView& dstProxyView) override { |
| 631 | SkASSERT(fDesc); |
| 632 | |
| 633 | GrGeometryProcessor* gp; |
| 634 | |
| 635 | { |
| 636 | const GrBackendFormat& backendFormat = |
| 637 | fViewCountPairs[0].fProxy->backendFormat(); |
| 638 | |
| 639 | GrSamplerState samplerState = GrSamplerState(GrSamplerState::WrapMode::kClamp, |
| 640 | fMetadata.filter()); |
| 641 | |
| 642 | gp = GrQuadPerEdgeAA::MakeTexturedProcessor( |
| 643 | arena, fDesc->fVertexSpec, *caps->shaderCaps(), backendFormat, samplerState, |
| 644 | fMetadata.fSwizzle, std::move(fTextureColorSpaceXform), fMetadata.saturate()); |
| 645 | |
| 646 | SkASSERT(fDesc->fVertexSpec.vertexSize() == gp->vertexStride()); |
| 647 | } |
| 648 | |
| 649 | auto pipelineFlags = (GrAAType::kMSAA == fMetadata.aaType()) ? |
| 650 | GrPipeline::InputFlags::kHWAntialias : GrPipeline::InputFlags::kNone; |
| 651 | |
| 652 | fDesc->fProgramInfo = GrSimpleMeshDrawOpHelper::CreateProgramInfo( |
Brian Salomon | 8afde5f | 2020-04-01 16:22:00 -0400 | [diff] [blame] | 653 | caps, arena, writeView, std::move(appliedClip), dstProxyView, gp, |
Chris Dalton | dbb833b | 2020-03-17 12:15:46 -0600 | [diff] [blame] | 654 | GrProcessorSet::MakeEmptySet(), fDesc->fVertexSpec.primitiveType(), |
| 655 | pipelineFlags); |
Robert Phillips | 4133dc4 | 2020-03-11 15:55:55 -0400 | [diff] [blame] | 656 | } |
| 657 | |
Robert Phillips | df70f15 | 2019-11-15 14:57:05 -0500 | [diff] [blame] | 658 | void onPrePrepareDraws(GrRecordingContext* context, |
Brian Salomon | 8afde5f | 2020-04-01 16:22:00 -0400 | [diff] [blame] | 659 | const GrSurfaceProxyView* writeView, |
Robert Phillips | 8053c97 | 2019-11-21 10:44:53 -0500 | [diff] [blame] | 660 | GrAppliedClip* clip, |
| 661 | const GrXferProcessor::DstProxyView& dstProxyView) override { |
Robert Phillips | 61fc799 | 2019-10-22 11:58:17 -0400 | [diff] [blame] | 662 | TRACE_EVENT0("skia.gpu", TRACE_FUNC); |
Robert Phillips | 29f3854 | 2019-10-16 09:20:25 -0400 | [diff] [blame] | 663 | |
Robert Phillips | 61fc799 | 2019-10-22 11:58:17 -0400 | [diff] [blame] | 664 | SkDEBUGCODE(this->validate();) |
Chris Dalton | dbb833b | 2020-03-17 12:15:46 -0600 | [diff] [blame] | 665 | SkASSERT(!fDesc); |
Robert Phillips | 61fc799 | 2019-10-22 11:58:17 -0400 | [diff] [blame] | 666 | |
Robert Phillips | d4fb7c7 | 2019-11-15 17:28:37 -0500 | [diff] [blame] | 667 | SkArenaAlloc* arena = context->priv().recordTimeAllocator(); |
Robert Phillips | 61fc799 | 2019-10-22 11:58:17 -0400 | [diff] [blame] | 668 | |
Chris Dalton | dbb833b | 2020-03-17 12:15:46 -0600 | [diff] [blame] | 669 | fDesc = arena->make<Desc>(); |
| 670 | this->characterize(fDesc); |
| 671 | fDesc->allocatePrePreparedVertices(arena); |
| 672 | FillInVertices(*context->priv().caps(), this, fDesc, fDesc->fPrePreparedVertices); |
Robert Phillips | 61fc799 | 2019-10-22 11:58:17 -0400 | [diff] [blame] | 673 | |
Chris Dalton | dbb833b | 2020-03-17 12:15:46 -0600 | [diff] [blame] | 674 | // This will call onCreateProgramInfo and register the created program with the DDL. |
Brian Salomon | 8afde5f | 2020-04-01 16:22:00 -0400 | [diff] [blame] | 675 | this->INHERITED::onPrePrepareDraws(context, writeView, clip, dstProxyView); |
Robert Phillips | bbd459d | 2019-10-29 14:40:03 -0400 | [diff] [blame] | 676 | } |
Robert Phillips | c5a2c75 | 2019-10-24 13:11:45 -0400 | [diff] [blame] | 677 | |
Chris Dalton | dbb833b | 2020-03-17 12:15:46 -0600 | [diff] [blame] | 678 | static void FillInVertices(const GrCaps& caps, TextureOp* texOp, Desc* desc, char* vertexData) { |
| 679 | SkASSERT(vertexData); |
| 680 | |
Robert Phillips | fd0c3b5 | 2019-11-01 08:44:42 -0400 | [diff] [blame] | 681 | int totQuadsSeen = 0; |
Robert Phillips | bbd459d | 2019-10-29 14:40:03 -0400 | [diff] [blame] | 682 | SkDEBUGCODE(int totVerticesSeen = 0;) |
Michael Ludwig | 189c980 | 2019-11-21 11:21:12 -0500 | [diff] [blame] | 683 | SkDEBUGCODE(const size_t vertexSize = desc->fVertexSpec.vertexSize()); |
Robert Phillips | c5a2c75 | 2019-10-24 13:11:45 -0400 | [diff] [blame] | 684 | |
Chris Dalton | dbb833b | 2020-03-17 12:15:46 -0600 | [diff] [blame] | 685 | GrQuadPerEdgeAA::Tessellator tessellator(desc->fVertexSpec, vertexData); |
Robert Phillips | bbd459d | 2019-10-29 14:40:03 -0400 | [diff] [blame] | 686 | for (const auto& op : ChainRange<TextureOp>(texOp)) { |
| 687 | auto iter = op.fQuads.iterator(); |
Michael Ludwig | adb12e7 | 2019-12-04 16:19:18 -0500 | [diff] [blame] | 688 | for (unsigned p = 0; p < op.fMetadata.fProxyCount; ++p) { |
Michael Ludwig | 189c980 | 2019-11-21 11:21:12 -0500 | [diff] [blame] | 689 | const int quadCnt = op.fViewCountPairs[p].fQuadCnt; |
| 690 | SkDEBUGCODE(int meshVertexCnt = quadCnt * desc->fVertexSpec.verticesPerQuad()); |
Robert Phillips | c5a2c75 | 2019-10-24 13:11:45 -0400 | [diff] [blame] | 691 | |
Chris Dalton | dbb833b | 2020-03-17 12:15:46 -0600 | [diff] [blame] | 692 | // Can just use top-left for origin here since we only need the dimensions to |
| 693 | // determine the texel size for insetting. |
| 694 | NormalizationParams params = proxy_normalization_params( |
| 695 | op.fViewCountPairs[p].fProxy.get(), kTopLeft_GrSurfaceOrigin); |
Michael Ludwig | 7c6a4a8 | 2020-02-07 10:14:26 -0500 | [diff] [blame] | 696 | |
Chris Dalton | dbb833b | 2020-03-17 12:15:46 -0600 | [diff] [blame] | 697 | bool inset = texOp->fMetadata.filter() != GrSamplerState::Filter::kNearest; |
Michael Ludwig | 7c6a4a8 | 2020-02-07 10:14:26 -0500 | [diff] [blame] | 698 | |
Chris Dalton | dbb833b | 2020-03-17 12:15:46 -0600 | [diff] [blame] | 699 | for (int i = 0; i < quadCnt && iter.next(); ++i) { |
| 700 | SkASSERT(iter.isLocalValid()); |
Brian Salomon | 2432d06 | 2020-04-16 20:48:09 -0400 | [diff] [blame^] | 701 | const ColorSubsetAndAA& info = iter.metadata(); |
Michael Ludwig | 7c6a4a8 | 2020-02-07 10:14:26 -0500 | [diff] [blame] | 702 | |
Chris Dalton | dbb833b | 2020-03-17 12:15:46 -0600 | [diff] [blame] | 703 | tessellator.append(iter.deviceQuad(), iter.localQuad(), info.fColor, |
Brian Salomon | 2432d06 | 2020-04-16 20:48:09 -0400 | [diff] [blame^] | 704 | inset ? inset_subset_for_bilerp(params, info.fSubsetRect) |
| 705 | : info.fSubsetRect, |
Chris Dalton | dbb833b | 2020-03-17 12:15:46 -0600 | [diff] [blame] | 706 | info.aaFlags()); |
Robert Phillips | c5a2c75 | 2019-10-24 13:11:45 -0400 | [diff] [blame] | 707 | } |
Robert Phillips | bbd459d | 2019-10-29 14:40:03 -0400 | [diff] [blame] | 708 | |
Chris Dalton | dbb833b | 2020-03-17 12:15:46 -0600 | [diff] [blame] | 709 | SkASSERT((totVerticesSeen + meshVertexCnt) * vertexSize |
| 710 | == (size_t)(tessellator.vertices() - vertexData)); |
Robert Phillips | bbd459d | 2019-10-29 14:40:03 -0400 | [diff] [blame] | 711 | |
Robert Phillips | fd0c3b5 | 2019-11-01 08:44:42 -0400 | [diff] [blame] | 712 | totQuadsSeen += quadCnt; |
| 713 | SkDEBUGCODE(totVerticesSeen += meshVertexCnt); |
| 714 | SkASSERT(totQuadsSeen * desc->fVertexSpec.verticesPerQuad() == totVerticesSeen); |
Robert Phillips | c5a2c75 | 2019-10-24 13:11:45 -0400 | [diff] [blame] | 715 | } |
| 716 | |
Robert Phillips | bbd459d | 2019-10-29 14:40:03 -0400 | [diff] [blame] | 717 | // If quad counts per proxy were calculated correctly, the entire iterator |
| 718 | // should have been consumed. |
Chris Dalton | dbb833b | 2020-03-17 12:15:46 -0600 | [diff] [blame] | 719 | SkASSERT(!iter.next()); |
Robert Phillips | c5a2c75 | 2019-10-24 13:11:45 -0400 | [diff] [blame] | 720 | } |
Robert Phillips | bbd459d | 2019-10-29 14:40:03 -0400 | [diff] [blame] | 721 | |
Chris Dalton | dbb833b | 2020-03-17 12:15:46 -0600 | [diff] [blame] | 722 | SkASSERT(desc->totalSizeInBytes() == (size_t)(tessellator.vertices() - vertexData)); |
Robert Phillips | bbd459d | 2019-10-29 14:40:03 -0400 | [diff] [blame] | 723 | SkASSERT(totQuadsSeen == desc->fNumTotalQuads); |
| 724 | SkASSERT(totVerticesSeen == desc->totalNumVertices()); |
Robert Phillips | 7327c9d | 2019-10-08 16:32:56 -0400 | [diff] [blame] | 725 | } |
| 726 | |
Robert Phillips | 29f3854 | 2019-10-16 09:20:25 -0400 | [diff] [blame] | 727 | #ifdef SK_DEBUG |
| 728 | void validate() const override { |
Michael Ludwig | fcdd061 | 2019-11-25 08:34:31 -0500 | [diff] [blame] | 729 | // NOTE: Since this is debug-only code, we use the virtual asTextureProxy() |
Michael Ludwig | adb12e7 | 2019-12-04 16:19:18 -0500 | [diff] [blame] | 730 | auto textureType = fViewCountPairs[0].fProxy->asTextureProxy()->textureType(); |
| 731 | GrAAType aaType = fMetadata.aaType(); |
Robert Phillips | 29f3854 | 2019-10-16 09:20:25 -0400 | [diff] [blame] | 732 | |
Robert Phillips | e837e61 | 2019-11-15 11:02:50 -0500 | [diff] [blame] | 733 | int quadCount = 0; |
Robert Phillips | 29f3854 | 2019-10-16 09:20:25 -0400 | [diff] [blame] | 734 | for (const auto& op : ChainRange<TextureOp>(this)) { |
Michael Ludwig | adb12e7 | 2019-12-04 16:19:18 -0500 | [diff] [blame] | 735 | SkASSERT(op.fMetadata.fSwizzle == fMetadata.fSwizzle); |
| 736 | |
| 737 | for (unsigned p = 0; p < op.fMetadata.fProxyCount; ++p) { |
| 738 | auto* proxy = op.fViewCountPairs[p].fProxy->asTextureProxy(); |
Robert Phillips | e837e61 | 2019-11-15 11:02:50 -0500 | [diff] [blame] | 739 | quadCount += op.fViewCountPairs[p].fQuadCnt; |
Robert Phillips | 29f3854 | 2019-10-16 09:20:25 -0400 | [diff] [blame] | 740 | SkASSERT(proxy); |
| 741 | SkASSERT(proxy->textureType() == textureType); |
Robert Phillips | 29f3854 | 2019-10-16 09:20:25 -0400 | [diff] [blame] | 742 | } |
| 743 | |
| 744 | // Each individual op must be a single aaType. kCoverage and kNone ops can chain |
| 745 | // together but kMSAA ones do not. |
| 746 | if (aaType == GrAAType::kCoverage || aaType == GrAAType::kNone) { |
Michael Ludwig | adb12e7 | 2019-12-04 16:19:18 -0500 | [diff] [blame] | 747 | SkASSERT(op.fMetadata.aaType() == GrAAType::kCoverage || |
| 748 | op.fMetadata.aaType() == GrAAType::kNone); |
Robert Phillips | 29f3854 | 2019-10-16 09:20:25 -0400 | [diff] [blame] | 749 | } else { |
Michael Ludwig | adb12e7 | 2019-12-04 16:19:18 -0500 | [diff] [blame] | 750 | SkASSERT(aaType == GrAAType::kMSAA && op.fMetadata.aaType() == GrAAType::kMSAA); |
Robert Phillips | 29f3854 | 2019-10-16 09:20:25 -0400 | [diff] [blame] | 751 | } |
| 752 | } |
Robert Phillips | e837e61 | 2019-11-15 11:02:50 -0500 | [diff] [blame] | 753 | |
| 754 | SkASSERT(quadCount == this->numChainedQuads()); |
Robert Phillips | 29f3854 | 2019-10-16 09:20:25 -0400 | [diff] [blame] | 755 | } |
| 756 | #endif |
| 757 | |
Robert Phillips | e837e61 | 2019-11-15 11:02:50 -0500 | [diff] [blame] | 758 | #if GR_TEST_UTILS |
| 759 | int numQuads() const final { return this->totNumQuads(); } |
| 760 | #endif |
| 761 | |
Chris Dalton | dbb833b | 2020-03-17 12:15:46 -0600 | [diff] [blame] | 762 | void characterize(Desc* desc) const { |
Robert Phillips | 29f3854 | 2019-10-16 09:20:25 -0400 | [diff] [blame] | 763 | GrQuad::Type quadType = GrQuad::Type::kAxisAligned; |
| 764 | ColorType colorType = ColorType::kNone; |
| 765 | GrQuad::Type srcQuadType = GrQuad::Type::kAxisAligned; |
Brian Salomon | 2432d06 | 2020-04-16 20:48:09 -0400 | [diff] [blame^] | 766 | Subset subset = Subset::kNo; |
Michael Ludwig | adb12e7 | 2019-12-04 16:19:18 -0500 | [diff] [blame] | 767 | GrAAType overallAAType = fMetadata.aaType(); |
Robert Phillips | 29f3854 | 2019-10-16 09:20:25 -0400 | [diff] [blame] | 768 | |
Robert Phillips | c554dcf | 2019-10-28 11:43:55 -0400 | [diff] [blame] | 769 | desc->fNumProxies = 0; |
| 770 | desc->fNumTotalQuads = 0; |
| 771 | int maxQuadsPerMesh = 0; |
Robert Phillips | 29f3854 | 2019-10-16 09:20:25 -0400 | [diff] [blame] | 772 | |
Brian Salomon | f723264 | 2018-09-19 08:58:08 -0400 | [diff] [blame] | 773 | for (const auto& op : ChainRange<TextureOp>(this)) { |
Michael Ludwig | 425eb45 | 2019-06-27 10:13:27 -0400 | [diff] [blame] | 774 | if (op.fQuads.deviceQuadType() > quadType) { |
| 775 | quadType = op.fQuads.deviceQuadType(); |
Michael Ludwig | f995c05 | 2018-11-26 15:24:29 -0500 | [diff] [blame] | 776 | } |
Michael Ludwig | 425eb45 | 2019-06-27 10:13:27 -0400 | [diff] [blame] | 777 | if (op.fQuads.localQuadType() > srcQuadType) { |
| 778 | srcQuadType = op.fQuads.localQuadType(); |
Michael Ludwig | 009b92e | 2019-02-15 16:03:53 -0500 | [diff] [blame] | 779 | } |
Brian Salomon | 2432d06 | 2020-04-16 20:48:09 -0400 | [diff] [blame^] | 780 | if (op.fMetadata.subset() == Subset::kYes) { |
| 781 | subset = Subset::kYes; |
Brian Salomon | f723264 | 2018-09-19 08:58:08 -0400 | [diff] [blame] | 782 | } |
Brian Osman | 788b916 | 2020-02-07 10:36:46 -0500 | [diff] [blame] | 783 | colorType = std::max(colorType, op.fMetadata.colorType()); |
Michael Ludwig | adb12e7 | 2019-12-04 16:19:18 -0500 | [diff] [blame] | 784 | desc->fNumProxies += op.fMetadata.fProxyCount; |
Robert Phillips | bbd459d | 2019-10-29 14:40:03 -0400 | [diff] [blame] | 785 | |
Michael Ludwig | adb12e7 | 2019-12-04 16:19:18 -0500 | [diff] [blame] | 786 | for (unsigned p = 0; p < op.fMetadata.fProxyCount; ++p) { |
Brian Osman | 788b916 | 2020-02-07 10:36:46 -0500 | [diff] [blame] | 787 | maxQuadsPerMesh = std::max(op.fViewCountPairs[p].fQuadCnt, maxQuadsPerMesh); |
Brian Salomon | f723264 | 2018-09-19 08:58:08 -0400 | [diff] [blame] | 788 | } |
Robert Phillips | bbd459d | 2019-10-29 14:40:03 -0400 | [diff] [blame] | 789 | desc->fNumTotalQuads += op.totNumQuads(); |
| 790 | |
Michael Ludwig | adb12e7 | 2019-12-04 16:19:18 -0500 | [diff] [blame] | 791 | if (op.fMetadata.aaType() == GrAAType::kCoverage) { |
Robert Phillips | 29f3854 | 2019-10-16 09:20:25 -0400 | [diff] [blame] | 792 | overallAAType = GrAAType::kCoverage; |
Brian Salomon | ae7d770 | 2018-10-14 15:05:45 -0400 | [diff] [blame] | 793 | } |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 794 | } |
Brian Salomon | 336ce7b | 2017-09-08 08:23:58 -0400 | [diff] [blame] | 795 | |
Robert Phillips | bbd459d | 2019-10-29 14:40:03 -0400 | [diff] [blame] | 796 | SkASSERT(desc->fNumTotalQuads == this->numChainedQuads()); |
| 797 | |
| 798 | SkASSERT(!CombinedQuadCountWillOverflow(overallAAType, false, desc->fNumTotalQuads)); |
| 799 | |
Robert Phillips | c554dcf | 2019-10-28 11:43:55 -0400 | [diff] [blame] | 800 | auto indexBufferOption = GrQuadPerEdgeAA::CalcIndexBufferOption(overallAAType, |
| 801 | maxQuadsPerMesh); |
| 802 | |
| 803 | desc->fVertexSpec = VertexSpec(quadType, colorType, srcQuadType, /* hasLocal */ true, |
Brian Salomon | 2432d06 | 2020-04-16 20:48:09 -0400 | [diff] [blame^] | 804 | subset, overallAAType, /* alpha as coverage */ true, |
Robert Phillips | c554dcf | 2019-10-28 11:43:55 -0400 | [diff] [blame] | 805 | indexBufferOption); |
Robert Phillips | e837e61 | 2019-11-15 11:02:50 -0500 | [diff] [blame] | 806 | |
| 807 | SkASSERT(desc->fNumTotalQuads <= GrQuadPerEdgeAA::QuadLimit(indexBufferOption)); |
Robert Phillips | 29f3854 | 2019-10-16 09:20:25 -0400 | [diff] [blame] | 808 | } |
Michael Ludwig | c182b94 | 2018-11-16 10:27:51 -0500 | [diff] [blame] | 809 | |
Robert Phillips | bbd459d | 2019-10-29 14:40:03 -0400 | [diff] [blame] | 810 | int totNumQuads() const { |
| 811 | #ifdef SK_DEBUG |
| 812 | int tmp = 0; |
Michael Ludwig | adb12e7 | 2019-12-04 16:19:18 -0500 | [diff] [blame] | 813 | for (unsigned p = 0; p < fMetadata.fProxyCount; ++p) { |
Greg Daniel | 549325c | 2019-10-30 16:19:20 -0400 | [diff] [blame] | 814 | tmp += fViewCountPairs[p].fQuadCnt; |
Robert Phillips | bbd459d | 2019-10-29 14:40:03 -0400 | [diff] [blame] | 815 | } |
Michael Ludwig | adb12e7 | 2019-12-04 16:19:18 -0500 | [diff] [blame] | 816 | SkASSERT(tmp == fMetadata.fTotalQuadCount); |
Robert Phillips | bbd459d | 2019-10-29 14:40:03 -0400 | [diff] [blame] | 817 | #endif |
| 818 | |
Michael Ludwig | adb12e7 | 2019-12-04 16:19:18 -0500 | [diff] [blame] | 819 | return fMetadata.fTotalQuadCount; |
Robert Phillips | bbd459d | 2019-10-29 14:40:03 -0400 | [diff] [blame] | 820 | } |
| 821 | |
| 822 | int numChainedQuads() const { |
| 823 | int numChainedQuads = this->totNumQuads(); |
| 824 | |
| 825 | for (const GrOp* tmp = this->prevInChain(); tmp; tmp = tmp->prevInChain()) { |
| 826 | numChainedQuads += ((const TextureOp*)tmp)->totNumQuads(); |
| 827 | } |
| 828 | |
| 829 | for (const GrOp* tmp = this->nextInChain(); tmp; tmp = tmp->nextInChain()) { |
| 830 | numChainedQuads += ((const TextureOp*)tmp)->totNumQuads(); |
| 831 | } |
| 832 | |
| 833 | return numChainedQuads; |
| 834 | } |
| 835 | |
Robert Phillips | 29f3854 | 2019-10-16 09:20:25 -0400 | [diff] [blame] | 836 | // onPrePrepareDraws may or may not have been called at this point |
| 837 | void onPrepareDraws(Target* target) override { |
| 838 | TRACE_EVENT0("skia.gpu", TRACE_FUNC); |
Greg Daniel | 7a82edf | 2018-12-04 10:54:34 -0500 | [diff] [blame] | 839 | |
Robert Phillips | 29f3854 | 2019-10-16 09:20:25 -0400 | [diff] [blame] | 840 | SkDEBUGCODE(this->validate();) |
| 841 | |
Chris Dalton | dbb833b | 2020-03-17 12:15:46 -0600 | [diff] [blame] | 842 | SkASSERT(!fDesc || fDesc->fPrePreparedVertices); |
Robert Phillips | 29f3854 | 2019-10-16 09:20:25 -0400 | [diff] [blame] | 843 | |
Chris Dalton | dbb833b | 2020-03-17 12:15:46 -0600 | [diff] [blame] | 844 | if (!fDesc) { |
Robert Phillips | 61fc799 | 2019-10-22 11:58:17 -0400 | [diff] [blame] | 845 | SkArenaAlloc* arena = target->allocator(); |
Chris Dalton | dbb833b | 2020-03-17 12:15:46 -0600 | [diff] [blame] | 846 | fDesc = arena->make<Desc>(); |
| 847 | this->characterize(fDesc); |
| 848 | SkASSERT(!fDesc->fPrePreparedVertices); |
Brian Salomon | f723264 | 2018-09-19 08:58:08 -0400 | [diff] [blame] | 849 | } |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 850 | |
Chris Dalton | dbb833b | 2020-03-17 12:15:46 -0600 | [diff] [blame] | 851 | size_t vertexSize = fDesc->fVertexSpec.vertexSize(); |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 852 | |
Chris Dalton | dbb833b | 2020-03-17 12:15:46 -0600 | [diff] [blame] | 853 | void* vdata = target->makeVertexSpace(vertexSize, fDesc->totalNumVertices(), |
| 854 | &fDesc->fVertexBuffer, &fDesc->fBaseVertex); |
Robert Phillips | bbd459d | 2019-10-29 14:40:03 -0400 | [diff] [blame] | 855 | if (!vdata) { |
| 856 | SkDebugf("Could not allocate vertices\n"); |
| 857 | return; |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 858 | } |
Robert Phillips | bbd459d | 2019-10-29 14:40:03 -0400 | [diff] [blame] | 859 | |
Chris Dalton | dbb833b | 2020-03-17 12:15:46 -0600 | [diff] [blame] | 860 | if (fDesc->fVertexSpec.needsIndexBuffer()) { |
| 861 | fDesc->fIndexBuffer = GrQuadPerEdgeAA::GetIndexBuffer( |
| 862 | target, fDesc->fVertexSpec.indexBufferOption()); |
| 863 | if (!fDesc->fIndexBuffer) { |
Robert Phillips | fd0c3b5 | 2019-11-01 08:44:42 -0400 | [diff] [blame] | 864 | SkDebugf("Could not allocate indices\n"); |
| 865 | return; |
| 866 | } |
| 867 | } |
| 868 | |
Chris Dalton | dbb833b | 2020-03-17 12:15:46 -0600 | [diff] [blame] | 869 | if (fDesc->fPrePreparedVertices) { |
| 870 | memcpy(vdata, fDesc->fPrePreparedVertices, fDesc->totalSizeInBytes()); |
Robert Phillips | bbd459d | 2019-10-29 14:40:03 -0400 | [diff] [blame] | 871 | } else { |
Chris Dalton | dbb833b | 2020-03-17 12:15:46 -0600 | [diff] [blame] | 872 | FillInVertices(target->caps(), this, fDesc, (char*) vdata); |
Robert Phillips | bbd459d | 2019-10-29 14:40:03 -0400 | [diff] [blame] | 873 | } |
Chris Dalton | 07cdcfc9 | 2019-02-26 11:13:22 -0700 | [diff] [blame] | 874 | } |
| 875 | |
| 876 | void onExecute(GrOpFlushState* flushState, const SkRect& chainBounds) override { |
Chris Dalton | dbb833b | 2020-03-17 12:15:46 -0600 | [diff] [blame] | 877 | if (!fDesc->fVertexBuffer) { |
| 878 | return; |
| 879 | } |
Robert Phillips | 3968fcb | 2019-12-05 16:40:31 -0500 | [diff] [blame] | 880 | |
Chris Dalton | dbb833b | 2020-03-17 12:15:46 -0600 | [diff] [blame] | 881 | if (fDesc->fVertexSpec.needsIndexBuffer() && !fDesc->fIndexBuffer) { |
| 882 | return; |
| 883 | } |
Robert Phillips | 3968fcb | 2019-12-05 16:40:31 -0500 | [diff] [blame] | 884 | |
Chris Dalton | dbb833b | 2020-03-17 12:15:46 -0600 | [diff] [blame] | 885 | if (!fDesc->fProgramInfo) { |
| 886 | this->createProgramInfo(flushState); |
| 887 | SkASSERT(fDesc->fProgramInfo); |
| 888 | } |
| 889 | |
| 890 | flushState->bindPipelineAndScissorClip(*fDesc->fProgramInfo, chainBounds); |
| 891 | flushState->bindBuffers(fDesc->fIndexBuffer.get(), nullptr, fDesc->fVertexBuffer.get()); |
| 892 | |
| 893 | int totQuadsSeen = 0; |
| 894 | SkDEBUGCODE(int numDraws = 0;) |
| 895 | for (const auto& op : ChainRange<TextureOp>(this)) { |
| 896 | for (unsigned p = 0; p < op.fMetadata.fProxyCount; ++p) { |
| 897 | const int quadCnt = op.fViewCountPairs[p].fQuadCnt; |
| 898 | SkASSERT(numDraws < fDesc->fNumProxies); |
| 899 | flushState->bindTextures(fDesc->fProgramInfo->primProc(), |
| 900 | *op.fViewCountPairs[p].fProxy, |
| 901 | fDesc->fProgramInfo->pipeline()); |
| 902 | GrQuadPerEdgeAA::IssueDraw(flushState->caps(), flushState->opsRenderPass(), |
| 903 | fDesc->fVertexSpec, totQuadsSeen, quadCnt, |
| 904 | fDesc->totalNumVertices(), fDesc->fBaseVertex); |
| 905 | totQuadsSeen += quadCnt; |
| 906 | SkDEBUGCODE(++numDraws;) |
| 907 | } |
| 908 | } |
| 909 | |
| 910 | SkASSERT(totQuadsSeen == fDesc->fNumTotalQuads); |
| 911 | SkASSERT(numDraws == fDesc->fNumProxies); |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 912 | } |
| 913 | |
Michael Ludwig | 28b0c5d | 2019-12-19 14:51:00 -0500 | [diff] [blame] | 914 | CombineResult onCombineIfPossible(GrOp* t, GrRecordingContext::Arenas*, |
| 915 | const GrCaps& caps) override { |
Brian Salomon | 5f39427 | 2019-07-02 14:07:49 -0400 | [diff] [blame] | 916 | TRACE_EVENT0("skia.gpu", TRACE_FUNC); |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 917 | const auto* that = t->cast<TextureOp>(); |
Robert Phillips | 7327c9d | 2019-10-08 16:32:56 -0400 | [diff] [blame] | 918 | |
Chris Dalton | dbb833b | 2020-03-17 12:15:46 -0600 | [diff] [blame] | 919 | if (fDesc || that->fDesc) { |
Robert Phillips | 7327c9d | 2019-10-08 16:32:56 -0400 | [diff] [blame] | 920 | // This should never happen (since only DDL recorded ops should be prePrepared) |
| 921 | // but, in any case, we should never combine ops that that been prePrepared |
| 922 | return CombineResult::kCannotCombine; |
| 923 | } |
| 924 | |
Brian Salomon | 2432d06 | 2020-04-16 20:48:09 -0400 | [diff] [blame^] | 925 | if (fMetadata.subset() != that->fMetadata.subset()) { |
| 926 | // It is technically possible to combine operations across subset modes, but performance |
Michael Ludwig | 2929f51 | 2019-04-19 13:05:56 -0400 | [diff] [blame] | 927 | // testing suggests it's better to make more draw calls where some take advantage of |
| 928 | // the more optimal shader path without coordinate clamping. |
| 929 | return CombineResult::kCannotCombine; |
| 930 | } |
Brian Osman | 3ebd354 | 2018-07-30 14:36:53 -0400 | [diff] [blame] | 931 | if (!GrColorSpaceXform::Equals(fTextureColorSpaceXform.get(), |
| 932 | that->fTextureColorSpaceXform.get())) { |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 933 | return CombineResult::kCannotCombine; |
Brian Osman | 3ebd354 | 2018-07-30 14:36:53 -0400 | [diff] [blame] | 934 | } |
Robert Phillips | b69001f | 2019-10-29 12:16:35 -0400 | [diff] [blame] | 935 | |
Brian Salomon | ae7d770 | 2018-10-14 15:05:45 -0400 | [diff] [blame] | 936 | bool upgradeToCoverageAAOnMerge = false; |
Michael Ludwig | adb12e7 | 2019-12-04 16:19:18 -0500 | [diff] [blame] | 937 | if (fMetadata.aaType() != that->fMetadata.aaType()) { |
| 938 | if (!CanUpgradeAAOnMerge(fMetadata.aaType(), that->fMetadata.aaType())) { |
Brian Salomon | ae7d770 | 2018-10-14 15:05:45 -0400 | [diff] [blame] | 939 | return CombineResult::kCannotCombine; |
| 940 | } |
| 941 | upgradeToCoverageAAOnMerge = true; |
Brian Salomon | b5ef1f9 | 2018-01-11 11:46:21 -0500 | [diff] [blame] | 942 | } |
Robert Phillips | b69001f | 2019-10-29 12:16:35 -0400 | [diff] [blame] | 943 | |
Michael Ludwig | adb12e7 | 2019-12-04 16:19:18 -0500 | [diff] [blame] | 944 | if (CombinedQuadCountWillOverflow(fMetadata.aaType(), upgradeToCoverageAAOnMerge, |
Robert Phillips | bbd459d | 2019-10-29 14:40:03 -0400 | [diff] [blame] | 945 | this->numChainedQuads() + that->numChainedQuads())) { |
| 946 | return CombineResult::kCannotCombine; |
Robert Phillips | b69001f | 2019-10-29 12:16:35 -0400 | [diff] [blame] | 947 | } |
| 948 | |
Michael Ludwig | adb12e7 | 2019-12-04 16:19:18 -0500 | [diff] [blame] | 949 | if (fMetadata.saturate() != that->fMetadata.saturate()) { |
Brian Salomon | f19f9ca | 2019-09-18 15:54:26 -0400 | [diff] [blame] | 950 | return CombineResult::kCannotCombine; |
| 951 | } |
Michael Ludwig | adb12e7 | 2019-12-04 16:19:18 -0500 | [diff] [blame] | 952 | if (fMetadata.filter() != that->fMetadata.filter()) { |
Brian Salomon | f723264 | 2018-09-19 08:58:08 -0400 | [diff] [blame] | 953 | return CombineResult::kCannotCombine; |
| 954 | } |
Michael Ludwig | adb12e7 | 2019-12-04 16:19:18 -0500 | [diff] [blame] | 955 | if (fMetadata.fSwizzle != that->fMetadata.fSwizzle) { |
| 956 | return CombineResult::kCannotCombine; |
| 957 | } |
| 958 | const auto* thisProxy = fViewCountPairs[0].fProxy.get(); |
| 959 | const auto* thatProxy = that->fViewCountPairs[0].fProxy.get(); |
| 960 | if (fMetadata.fProxyCount > 1 || that->fMetadata.fProxyCount > 1 || |
| 961 | thisProxy != thatProxy) { |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 962 | // 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] | 963 | if (GrTextureProxy::ProxiesAreCompatibleAsDynamicState(thisProxy, thatProxy) && |
Michael Ludwig | adb12e7 | 2019-12-04 16:19:18 -0500 | [diff] [blame] | 964 | caps.dynamicStateArrayGeometryProcessorTextureSupport()) { |
Brian Salomon | f723264 | 2018-09-19 08:58:08 -0400 | [diff] [blame] | 965 | return CombineResult::kMayChain; |
| 966 | } |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 967 | return CombineResult::kCannotCombine; |
Brian Salomon | 336ce7b | 2017-09-08 08:23:58 -0400 | [diff] [blame] | 968 | } |
Michael Ludwig | 009b92e | 2019-02-15 16:03:53 -0500 | [diff] [blame] | 969 | |
Brian Salomon | 2432d06 | 2020-04-16 20:48:09 -0400 | [diff] [blame^] | 970 | fMetadata.fSubset |= that->fMetadata.fSubset; |
Brian Osman | 788b916 | 2020-02-07 10:36:46 -0500 | [diff] [blame] | 971 | fMetadata.fColorType = std::max(fMetadata.fColorType, that->fMetadata.fColorType); |
Brian Salomon | ae7d770 | 2018-10-14 15:05:45 -0400 | [diff] [blame] | 972 | if (upgradeToCoverageAAOnMerge) { |
Michael Ludwig | 4384f04 | 2019-12-05 10:30:35 -0500 | [diff] [blame] | 973 | fMetadata.fAAType = static_cast<uint16_t>(GrAAType::kCoverage); |
Brian Salomon | ae7d770 | 2018-10-14 15:05:45 -0400 | [diff] [blame] | 974 | } |
Michael Ludwig | 009b92e | 2019-02-15 16:03:53 -0500 | [diff] [blame] | 975 | |
Michael Ludwig | 425eb45 | 2019-06-27 10:13:27 -0400 | [diff] [blame] | 976 | // Concatenate quad lists together |
Michael Ludwig | 009b92e | 2019-02-15 16:03:53 -0500 | [diff] [blame] | 977 | fQuads.concat(that->fQuads); |
Greg Daniel | 549325c | 2019-10-30 16:19:20 -0400 | [diff] [blame] | 978 | fViewCountPairs[0].fQuadCnt += that->fQuads.count(); |
Michael Ludwig | adb12e7 | 2019-12-04 16:19:18 -0500 | [diff] [blame] | 979 | fMetadata.fTotalQuadCount += that->fQuads.count(); |
Michael Ludwig | 009b92e | 2019-02-15 16:03:53 -0500 | [diff] [blame] | 980 | |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 981 | return CombineResult::kMerged; |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 982 | } |
| 983 | |
Brian Salomon | 2432d06 | 2020-04-16 20:48:09 -0400 | [diff] [blame^] | 984 | GrQuadBuffer<ColorSubsetAndAA> fQuads; |
Brian Osman | 3ebd354 | 2018-07-30 14:36:53 -0400 | [diff] [blame] | 985 | sk_sp<GrColorSpaceXform> fTextureColorSpaceXform; |
Chris Dalton | dbb833b | 2020-03-17 12:15:46 -0600 | [diff] [blame] | 986 | // Most state of TextureOp is packed into these two field to minimize the op's size. |
Michael Ludwig | adb12e7 | 2019-12-04 16:19:18 -0500 | [diff] [blame] | 987 | // Historically, increasing the size of TextureOp has caused surprising perf regressions, so |
| 988 | // consider/measure changes with care. |
Chris Dalton | dbb833b | 2020-03-17 12:15:46 -0600 | [diff] [blame] | 989 | Desc* fDesc; |
Michael Ludwig | adb12e7 | 2019-12-04 16:19:18 -0500 | [diff] [blame] | 990 | Metadata fMetadata; |
Robert Phillips | 32803ff | 2019-10-23 08:26:08 -0400 | [diff] [blame] | 991 | |
| 992 | // This field must go last. When allocating this op, we will allocate extra space to hold |
Greg Daniel | 549325c | 2019-10-30 16:19:20 -0400 | [diff] [blame] | 993 | // additional ViewCountPairs immediately after the op's allocation so we can treat this |
Robert Phillips | 32803ff | 2019-10-23 08:26:08 -0400 | [diff] [blame] | 994 | // as an fProxyCnt-length array. |
Greg Daniel | 549325c | 2019-10-30 16:19:20 -0400 | [diff] [blame] | 995 | ViewCountPair fViewCountPairs[1]; |
Brian Salomon | 336ce7b | 2017-09-08 08:23:58 -0400 | [diff] [blame] | 996 | |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 997 | typedef GrMeshDrawOp INHERITED; |
| 998 | }; |
| 999 | |
| 1000 | } // anonymous namespace |
| 1001 | |
Robert Phillips | e837e61 | 2019-11-15 11:02:50 -0500 | [diff] [blame] | 1002 | #if GR_TEST_UTILS |
| 1003 | uint32_t GrTextureOp::ClassID() { |
| 1004 | return TextureOp::ClassID(); |
| 1005 | } |
| 1006 | #endif |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 1007 | |
Robert Phillips | e837e61 | 2019-11-15 11:02:50 -0500 | [diff] [blame] | 1008 | std::unique_ptr<GrDrawOp> GrTextureOp::Make(GrRecordingContext* context, |
| 1009 | GrSurfaceProxyView proxyView, |
Brian Salomon | fc11844 | 2019-11-22 19:09:27 -0500 | [diff] [blame] | 1010 | SkAlphaType alphaType, |
Robert Phillips | e837e61 | 2019-11-15 11:02:50 -0500 | [diff] [blame] | 1011 | sk_sp<GrColorSpaceXform> textureXform, |
| 1012 | GrSamplerState::Filter filter, |
| 1013 | const SkPMColor4f& color, |
| 1014 | Saturate saturate, |
| 1015 | SkBlendMode blendMode, |
| 1016 | GrAAType aaType, |
Michael Ludwig | 6b45c5d | 2020-02-07 09:56:38 -0500 | [diff] [blame] | 1017 | DrawQuad* quad, |
Brian Salomon | 2432d06 | 2020-04-16 20:48:09 -0400 | [diff] [blame^] | 1018 | const SkRect* subset) { |
Michael Ludwig | 22429f9 | 2019-06-27 10:44:48 -0400 | [diff] [blame] | 1019 | // Apply optimizations that are valid whether or not using GrTextureOp or GrFillRectOp |
Brian Salomon | 2432d06 | 2020-04-16 20:48:09 -0400 | [diff] [blame^] | 1020 | if (subset && subset->contains(proxyView.proxy()->backingStoreBoundsRect())) { |
| 1021 | // No need for a shader-based subset if hardware clamping achieves the same effect |
| 1022 | subset = nullptr; |
Michael Ludwig | 22429f9 | 2019-06-27 10:44:48 -0400 | [diff] [blame] | 1023 | } |
| 1024 | |
Michael Ludwig | 6b45c5d | 2020-02-07 09:56:38 -0500 | [diff] [blame] | 1025 | if (filter != GrSamplerState::Filter::kNearest && |
| 1026 | !filter_has_effect(quad->fLocal, quad->fDevice)) { |
Michael Ludwig | 22429f9 | 2019-06-27 10:44:48 -0400 | [diff] [blame] | 1027 | filter = GrSamplerState::Filter::kNearest; |
| 1028 | } |
| 1029 | |
| 1030 | if (blendMode == SkBlendMode::kSrcOver) { |
Greg Daniel | 549325c | 2019-10-30 16:19:20 -0400 | [diff] [blame] | 1031 | return TextureOp::Make(context, std::move(proxyView), std::move(textureXform), filter, |
Brian Salomon | 2432d06 | 2020-04-16 20:48:09 -0400 | [diff] [blame^] | 1032 | color, saturate, aaType, std::move(quad), subset); |
Michael Ludwig | 22429f9 | 2019-06-27 10:44:48 -0400 | [diff] [blame] | 1033 | } else { |
| 1034 | // Emulate complex blending using GrFillRectOp |
| 1035 | GrPaint paint; |
| 1036 | paint.setColor4f(color); |
| 1037 | paint.setXPFactory(SkBlendMode_AsXPFactory(blendMode)); |
| 1038 | |
| 1039 | std::unique_ptr<GrFragmentProcessor> fp; |
Brian Salomon | 2432d06 | 2020-04-16 20:48:09 -0400 | [diff] [blame^] | 1040 | if (subset) { |
Brian Salomon | ca6b2f4 | 2020-01-24 11:31:21 -0500 | [diff] [blame] | 1041 | const auto& caps = *context->priv().caps(); |
| 1042 | SkRect localRect; |
Michael Ludwig | 6b45c5d | 2020-02-07 09:56:38 -0500 | [diff] [blame] | 1043 | if (quad->fLocal.asRect(&localRect)) { |
Brian Salomon | ed729f9 | 2020-02-05 12:15:18 -0500 | [diff] [blame] | 1044 | fp = GrTextureEffect::MakeSubset(std::move(proxyView), alphaType, SkMatrix::I(), filter, |
Brian Salomon | 2432d06 | 2020-04-16 20:48:09 -0400 | [diff] [blame^] | 1045 | *subset, localRect, caps); |
Brian Salomon | ca6b2f4 | 2020-01-24 11:31:21 -0500 | [diff] [blame] | 1046 | } else { |
Brian Salomon | ed729f9 | 2020-02-05 12:15:18 -0500 | [diff] [blame] | 1047 | fp = GrTextureEffect::MakeSubset(std::move(proxyView), alphaType, SkMatrix::I(), filter, |
Brian Salomon | 2432d06 | 2020-04-16 20:48:09 -0400 | [diff] [blame^] | 1048 | *subset, caps); |
Brian Salomon | ca6b2f4 | 2020-01-24 11:31:21 -0500 | [diff] [blame] | 1049 | } |
| 1050 | } else { |
Greg Daniel | d2ccbb5 | 2020-02-05 10:45:39 -0500 | [diff] [blame] | 1051 | fp = GrTextureEffect::Make(std::move(proxyView), alphaType, SkMatrix::I(), filter); |
Michael Ludwig | 22429f9 | 2019-06-27 10:44:48 -0400 | [diff] [blame] | 1052 | } |
| 1053 | fp = GrColorSpaceXformEffect::Make(std::move(fp), std::move(textureXform)); |
| 1054 | paint.addColorFragmentProcessor(std::move(fp)); |
Brian Salomon | f19f9ca | 2019-09-18 15:54:26 -0400 | [diff] [blame] | 1055 | if (saturate == GrTextureOp::Saturate::kYes) { |
Brian Osman | 6f5e940 | 2020-01-22 10:39:31 -0500 | [diff] [blame] | 1056 | paint.addColorFragmentProcessor(GrClampFragmentProcessor::Make(false)); |
Brian Salomon | f19f9ca | 2019-09-18 15:54:26 -0400 | [diff] [blame] | 1057 | } |
Michael Ludwig | 22429f9 | 2019-06-27 10:44:48 -0400 | [diff] [blame] | 1058 | |
Michael Ludwig | 6b45c5d | 2020-02-07 09:56:38 -0500 | [diff] [blame] | 1059 | return GrFillRectOp::Make(context, std::move(paint), aaType, quad); |
Michael Ludwig | 22429f9 | 2019-06-27 10:44:48 -0400 | [diff] [blame] | 1060 | } |
| 1061 | } |
| 1062 | |
Robert Phillips | e837e61 | 2019-11-15 11:02:50 -0500 | [diff] [blame] | 1063 | // A helper class that assists in breaking up bulk API quad draws into manageable chunks. |
| 1064 | class GrTextureOp::BatchSizeLimiter { |
| 1065 | public: |
| 1066 | BatchSizeLimiter(GrRenderTargetContext* rtc, |
| 1067 | const GrClip& clip, |
| 1068 | GrRecordingContext* context, |
| 1069 | int numEntries, |
| 1070 | GrSamplerState::Filter filter, |
| 1071 | GrTextureOp::Saturate saturate, |
| 1072 | SkCanvas::SrcRectConstraint constraint, |
| 1073 | const SkMatrix& viewMatrix, |
| 1074 | sk_sp<GrColorSpaceXform> textureColorSpaceXform) |
| 1075 | : fRTC(rtc) |
| 1076 | , fClip(clip) |
| 1077 | , fContext(context) |
| 1078 | , fFilter(filter) |
| 1079 | , fSaturate(saturate) |
| 1080 | , fConstraint(constraint) |
| 1081 | , fViewMatrix(viewMatrix) |
| 1082 | , fTextureColorSpaceXform(textureColorSpaceXform) |
| 1083 | , fNumLeft(numEntries) { |
| 1084 | } |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 1085 | |
Michael Ludwig | adb12e7 | 2019-12-04 16:19:18 -0500 | [diff] [blame] | 1086 | void createOp(GrRenderTargetContext::TextureSetEntry set[], |
Robert Phillips | e837e61 | 2019-11-15 11:02:50 -0500 | [diff] [blame] | 1087 | int clumpSize, |
| 1088 | GrAAType aaType) { |
Michael Ludwig | 379e496 | 2019-12-06 13:21:26 -0500 | [diff] [blame] | 1089 | int clumpProxyCount = proxy_run_count(&set[fNumClumped], clumpSize); |
Robert Phillips | e837e61 | 2019-11-15 11:02:50 -0500 | [diff] [blame] | 1090 | std::unique_ptr<GrDrawOp> op = TextureOp::Make(fContext, &set[fNumClumped], clumpSize, |
Michael Ludwig | 379e496 | 2019-12-06 13:21:26 -0500 | [diff] [blame] | 1091 | clumpProxyCount, fFilter, fSaturate, aaType, |
Robert Phillips | e837e61 | 2019-11-15 11:02:50 -0500 | [diff] [blame] | 1092 | fConstraint, fViewMatrix, |
| 1093 | fTextureColorSpaceXform); |
| 1094 | fRTC->addDrawOp(fClip, std::move(op)); |
| 1095 | |
| 1096 | fNumLeft -= clumpSize; |
| 1097 | fNumClumped += clumpSize; |
| 1098 | } |
| 1099 | |
| 1100 | int numLeft() const { return fNumLeft; } |
| 1101 | int baseIndex() const { return fNumClumped; } |
| 1102 | |
| 1103 | private: |
| 1104 | GrRenderTargetContext* fRTC; |
| 1105 | const GrClip& fClip; |
| 1106 | GrRecordingContext* fContext; |
| 1107 | GrSamplerState::Filter fFilter; |
| 1108 | GrTextureOp::Saturate fSaturate; |
| 1109 | SkCanvas::SrcRectConstraint fConstraint; |
| 1110 | const SkMatrix& fViewMatrix; |
| 1111 | sk_sp<GrColorSpaceXform> fTextureColorSpaceXform; |
| 1112 | |
| 1113 | int fNumLeft; |
| 1114 | int fNumClumped = 0; // also the offset for the start of the next clump |
| 1115 | }; |
| 1116 | |
| 1117 | // Greedily clump quad draws together until the index buffer limit is exceeded. |
Michael Ludwig | fe13ca3 | 2019-11-21 10:26:41 -0500 | [diff] [blame] | 1118 | void GrTextureOp::AddTextureSetOps(GrRenderTargetContext* rtc, |
| 1119 | const GrClip& clip, |
| 1120 | GrRecordingContext* context, |
Michael Ludwig | adb12e7 | 2019-12-04 16:19:18 -0500 | [diff] [blame] | 1121 | GrRenderTargetContext::TextureSetEntry set[], |
Michael Ludwig | fe13ca3 | 2019-11-21 10:26:41 -0500 | [diff] [blame] | 1122 | int cnt, |
Michael Ludwig | 379e496 | 2019-12-06 13:21:26 -0500 | [diff] [blame] | 1123 | int proxyRunCnt, |
Michael Ludwig | fe13ca3 | 2019-11-21 10:26:41 -0500 | [diff] [blame] | 1124 | GrSamplerState::Filter filter, |
| 1125 | Saturate saturate, |
| 1126 | SkBlendMode blendMode, |
| 1127 | GrAAType aaType, |
| 1128 | SkCanvas::SrcRectConstraint constraint, |
| 1129 | const SkMatrix& viewMatrix, |
| 1130 | sk_sp<GrColorSpaceXform> textureColorSpaceXform) { |
Michael Ludwig | 379e496 | 2019-12-06 13:21:26 -0500 | [diff] [blame] | 1131 | // Ensure that the index buffer limits are lower than the proxy and quad count limits of |
| 1132 | // the op's metadata so we don't need to worry about overflow. |
Michael Ludwig | 4ef1ca1 | 2019-12-19 10:58:52 -0500 | [diff] [blame] | 1133 | SkDEBUGCODE(TextureOp::ValidateResourceLimits();) |
Michael Ludwig | 379e496 | 2019-12-06 13:21:26 -0500 | [diff] [blame] | 1134 | SkASSERT(proxy_run_count(set, cnt) == proxyRunCnt); |
| 1135 | |
Michael Ludwig | fe13ca3 | 2019-11-21 10:26:41 -0500 | [diff] [blame] | 1136 | // First check if we can support batches as a single op |
| 1137 | if (blendMode != SkBlendMode::kSrcOver || |
| 1138 | !context->priv().caps()->dynamicStateArrayGeometryProcessorTextureSupport()) { |
| 1139 | // Append each entry as its own op; these may still be GrTextureOps if the blend mode is |
| 1140 | // src-over but the backend doesn't support dynamic state changes. Otherwise Make() |
| 1141 | // automatically creates the appropriate GrFillRectOp to emulate GrTextureOp. |
| 1142 | SkMatrix ctm; |
| 1143 | for (int i = 0; i < cnt; ++i) { |
| 1144 | float alpha = set[i].fAlpha; |
| 1145 | ctm = viewMatrix; |
| 1146 | if (set[i].fPreViewMatrix) { |
| 1147 | ctm.preConcat(*set[i].fPreViewMatrix); |
| 1148 | } |
Robert Phillips | e837e61 | 2019-11-15 11:02:50 -0500 | [diff] [blame] | 1149 | |
Michael Ludwig | 6b45c5d | 2020-02-07 09:56:38 -0500 | [diff] [blame] | 1150 | DrawQuad quad; |
| 1151 | quad.fEdgeFlags = set[i].fAAFlags; |
Michael Ludwig | fe13ca3 | 2019-11-21 10:26:41 -0500 | [diff] [blame] | 1152 | if (set[i].fDstClipQuad) { |
Michael Ludwig | 6b45c5d | 2020-02-07 09:56:38 -0500 | [diff] [blame] | 1153 | quad.fDevice = GrQuad::MakeFromSkQuad(set[i].fDstClipQuad, ctm); |
Michael Ludwig | fe13ca3 | 2019-11-21 10:26:41 -0500 | [diff] [blame] | 1154 | |
| 1155 | SkPoint srcPts[4]; |
| 1156 | GrMapRectPoints(set[i].fDstRect, set[i].fSrcRect, set[i].fDstClipQuad, srcPts, 4); |
Michael Ludwig | 6b45c5d | 2020-02-07 09:56:38 -0500 | [diff] [blame] | 1157 | quad.fLocal = GrQuad::MakeFromSkQuad(srcPts, SkMatrix::I()); |
Michael Ludwig | fe13ca3 | 2019-11-21 10:26:41 -0500 | [diff] [blame] | 1158 | } else { |
Michael Ludwig | 6b45c5d | 2020-02-07 09:56:38 -0500 | [diff] [blame] | 1159 | quad.fDevice = GrQuad::MakeFromRect(set[i].fDstRect, ctm); |
| 1160 | quad.fLocal = GrQuad(set[i].fSrcRect); |
Michael Ludwig | fe13ca3 | 2019-11-21 10:26:41 -0500 | [diff] [blame] | 1161 | } |
| 1162 | |
Brian Salomon | 2432d06 | 2020-04-16 20:48:09 -0400 | [diff] [blame^] | 1163 | const SkRect* subset = constraint == SkCanvas::kStrict_SrcRectConstraint |
Michael Ludwig | fe13ca3 | 2019-11-21 10:26:41 -0500 | [diff] [blame] | 1164 | ? &set[i].fSrcRect : nullptr; |
| 1165 | |
Brian Salomon | fc11844 | 2019-11-22 19:09:27 -0500 | [diff] [blame] | 1166 | auto op = Make(context, set[i].fProxyView, set[i].fSrcAlphaType, textureColorSpaceXform, |
Michael Ludwig | fe13ca3 | 2019-11-21 10:26:41 -0500 | [diff] [blame] | 1167 | filter, {alpha, alpha, alpha, alpha}, saturate, blendMode, aaType, |
Brian Salomon | 2432d06 | 2020-04-16 20:48:09 -0400 | [diff] [blame^] | 1168 | &quad, subset); |
Michael Ludwig | fe13ca3 | 2019-11-21 10:26:41 -0500 | [diff] [blame] | 1169 | rtc->addDrawOp(clip, std::move(op)); |
| 1170 | } |
| 1171 | return; |
| 1172 | } |
| 1173 | |
| 1174 | // Second check if we can always just make a single op and avoid the extra iteration |
Robert Phillips | e837e61 | 2019-11-15 11:02:50 -0500 | [diff] [blame] | 1175 | // needed to clump things together. |
Brian Osman | 788b916 | 2020-02-07 10:36:46 -0500 | [diff] [blame] | 1176 | if (cnt <= std::min(GrResourceProvider::MaxNumNonAAQuads(), |
Robert Phillips | e837e61 | 2019-11-15 11:02:50 -0500 | [diff] [blame] | 1177 | GrResourceProvider::MaxNumAAQuads())) { |
Michael Ludwig | 379e496 | 2019-12-06 13:21:26 -0500 | [diff] [blame] | 1178 | auto op = TextureOp::Make(context, set, cnt, proxyRunCnt, filter, saturate, aaType, |
Robert Phillips | e837e61 | 2019-11-15 11:02:50 -0500 | [diff] [blame] | 1179 | constraint, viewMatrix, std::move(textureColorSpaceXform)); |
| 1180 | rtc->addDrawOp(clip, std::move(op)); |
| 1181 | return; |
| 1182 | } |
| 1183 | |
| 1184 | BatchSizeLimiter state(rtc, clip, context, cnt, filter, saturate, constraint, viewMatrix, |
| 1185 | std::move(textureColorSpaceXform)); |
| 1186 | |
| 1187 | // kNone and kMSAA never get altered |
| 1188 | if (aaType == GrAAType::kNone || aaType == GrAAType::kMSAA) { |
| 1189 | // Clump these into series of MaxNumNonAAQuads-sized GrTextureOps |
| 1190 | while (state.numLeft() > 0) { |
Brian Osman | 788b916 | 2020-02-07 10:36:46 -0500 | [diff] [blame] | 1191 | int clumpSize = std::min(state.numLeft(), GrResourceProvider::MaxNumNonAAQuads()); |
Robert Phillips | e837e61 | 2019-11-15 11:02:50 -0500 | [diff] [blame] | 1192 | |
| 1193 | state.createOp(set, clumpSize, aaType); |
| 1194 | } |
| 1195 | } else { |
| 1196 | // kCoverage can be downgraded to kNone. Note that the following is conservative. kCoverage |
| 1197 | // can also get downgraded to kNone if all the quads are on integer coordinates and |
| 1198 | // axis-aligned. |
| 1199 | SkASSERT(aaType == GrAAType::kCoverage); |
| 1200 | |
| 1201 | while (state.numLeft() > 0) { |
| 1202 | GrAAType runningAA = GrAAType::kNone; |
| 1203 | bool clumped = false; |
| 1204 | |
| 1205 | for (int i = 0; i < state.numLeft(); ++i) { |
| 1206 | int absIndex = state.baseIndex() + i; |
| 1207 | |
| 1208 | if (set[absIndex].fAAFlags != GrQuadAAFlags::kNone) { |
| 1209 | |
| 1210 | if (i >= GrResourceProvider::MaxNumAAQuads()) { |
| 1211 | // Here we either need to boost the AA type to kCoverage, but doing so with |
| 1212 | // all the accumulated quads would overflow, or we have a set of AA quads |
| 1213 | // that has just gotten too large. In either case, calve off the existing |
| 1214 | // quads as their own TextureOp. |
| 1215 | state.createOp( |
| 1216 | set, |
| 1217 | runningAA == GrAAType::kNone ? i : GrResourceProvider::MaxNumAAQuads(), |
| 1218 | runningAA); // maybe downgrading AA here |
| 1219 | clumped = true; |
| 1220 | break; |
| 1221 | } |
| 1222 | |
| 1223 | runningAA = GrAAType::kCoverage; |
| 1224 | } else if (runningAA == GrAAType::kNone) { |
| 1225 | |
| 1226 | if (i >= GrResourceProvider::MaxNumNonAAQuads()) { |
| 1227 | // Here we've found a consistent batch of non-AA quads that has gotten too |
| 1228 | // large. Calve it off as its own GrTextureOp. |
| 1229 | state.createOp(set, GrResourceProvider::MaxNumNonAAQuads(), |
| 1230 | GrAAType::kNone); // definitely downgrading AA here |
| 1231 | clumped = true; |
| 1232 | break; |
| 1233 | } |
| 1234 | } |
| 1235 | } |
| 1236 | |
| 1237 | if (!clumped) { |
| 1238 | // We ran through the above loop w/o hitting a limit. Spit out this last clump of |
| 1239 | // quads and call it a day. |
| 1240 | state.createOp(set, state.numLeft(), runningAA); // maybe downgrading AA here |
| 1241 | } |
| 1242 | } |
| 1243 | } |
| 1244 | } |
Robert Phillips | ae01f62 | 2019-11-13 15:56:31 +0000 | [diff] [blame] | 1245 | |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 1246 | #if GR_TEST_UTILS |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 1247 | #include "include/private/GrRecordingContext.h" |
| 1248 | #include "src/gpu/GrProxyProvider.h" |
| 1249 | #include "src/gpu/GrRecordingContextPriv.h" |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 1250 | |
| 1251 | GR_DRAW_OP_TEST_DEFINE(TextureOp) { |
Brian Salomon | a56a746 | 2020-02-07 14:17:25 -0500 | [diff] [blame] | 1252 | SkISize dims; |
| 1253 | dims.fHeight = random->nextULessThan(90) + 10; |
| 1254 | dims.fWidth = random->nextULessThan(90) + 10; |
Brian Salomon | 2a4f983 | 2018-03-03 22:43:43 -0500 | [diff] [blame] | 1255 | auto origin = random->nextBool() ? kTopLeft_GrSurfaceOrigin : kBottomLeft_GrSurfaceOrigin; |
Greg Daniel | 09c9400 | 2018-06-08 22:11:51 +0000 | [diff] [blame] | 1256 | GrMipMapped mipMapped = random->nextBool() ? GrMipMapped::kYes : GrMipMapped::kNo; |
| 1257 | SkBackingFit fit = SkBackingFit::kExact; |
| 1258 | if (mipMapped == GrMipMapped::kNo) { |
| 1259 | fit = random->nextBool() ? SkBackingFit::kApprox : SkBackingFit::kExact; |
| 1260 | } |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 1261 | const GrBackendFormat format = |
Robert Phillips | 0a15cc6 | 2019-07-30 12:49:10 -0400 | [diff] [blame] | 1262 | context->priv().caps()->getDefaultBackendFormat(GrColorType::kRGBA_8888, |
| 1263 | GrRenderable::kNo); |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 1264 | GrProxyProvider* proxyProvider = context->priv().proxyProvider(); |
Brian Salomon | e8a766b | 2019-07-19 14:24:36 -0400 | [diff] [blame] | 1265 | sk_sp<GrTextureProxy> proxy = proxyProvider->createProxy( |
Brian Salomon | df1bd6d | 2020-03-26 20:37:01 -0400 | [diff] [blame] | 1266 | format, dims, GrRenderable::kNo, 1, mipMapped, fit, SkBudgeted::kNo, GrProtected::kNo, |
| 1267 | GrInternalSurfaceFlags::kNone); |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 1268 | |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 1269 | SkRect rect = GrTest::TestRect(random); |
| 1270 | SkRect srcRect; |
| 1271 | srcRect.fLeft = random->nextRangeScalar(0.f, proxy->width() / 2.f); |
| 1272 | srcRect.fRight = random->nextRangeScalar(0.f, proxy->width()) + proxy->width() / 2.f; |
| 1273 | srcRect.fTop = random->nextRangeScalar(0.f, proxy->height() / 2.f); |
| 1274 | srcRect.fBottom = random->nextRangeScalar(0.f, proxy->height()) + proxy->height() / 2.f; |
| 1275 | SkMatrix viewMatrix = GrTest::TestMatrixPreservesRightAngles(random); |
Brian Osman | 3d139a4 | 2018-11-19 10:42:10 -0500 | [diff] [blame] | 1276 | SkPMColor4f color = SkPMColor4f::FromBytes_RGBA(SkColorToPremulGrColor(random->nextU())); |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 1277 | GrSamplerState::Filter filter = (GrSamplerState::Filter)random->nextULessThan( |
| 1278 | static_cast<uint32_t>(GrSamplerState::Filter::kMipMap) + 1); |
Greg Daniel | 09c9400 | 2018-06-08 22:11:51 +0000 | [diff] [blame] | 1279 | while (mipMapped == GrMipMapped::kNo && filter == GrSamplerState::Filter::kMipMap) { |
| 1280 | filter = (GrSamplerState::Filter)random->nextULessThan( |
| 1281 | static_cast<uint32_t>(GrSamplerState::Filter::kMipMap) + 1); |
| 1282 | } |
Brian Osman | 3ebd354 | 2018-07-30 14:36:53 -0400 | [diff] [blame] | 1283 | auto texXform = GrTest::TestColorXform(random); |
Brian Salomon | 485b8c6 | 2018-01-12 15:11:06 -0500 | [diff] [blame] | 1284 | GrAAType aaType = GrAAType::kNone; |
| 1285 | if (random->nextBool()) { |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 1286 | aaType = (numSamples > 1) ? GrAAType::kMSAA : GrAAType::kCoverage; |
Brian Salomon | 485b8c6 | 2018-01-12 15:11:06 -0500 | [diff] [blame] | 1287 | } |
Brian Salomon | 2213ee9 | 2018-10-02 10:44:21 -0400 | [diff] [blame] | 1288 | GrQuadAAFlags aaFlags = GrQuadAAFlags::kNone; |
| 1289 | aaFlags |= random->nextBool() ? GrQuadAAFlags::kLeft : GrQuadAAFlags::kNone; |
| 1290 | aaFlags |= random->nextBool() ? GrQuadAAFlags::kTop : GrQuadAAFlags::kNone; |
| 1291 | aaFlags |= random->nextBool() ? GrQuadAAFlags::kRight : GrQuadAAFlags::kNone; |
| 1292 | aaFlags |= random->nextBool() ? GrQuadAAFlags::kBottom : GrQuadAAFlags::kNone; |
Brian Salomon | 2432d06 | 2020-04-16 20:48:09 -0400 | [diff] [blame^] | 1293 | bool useSubset = random->nextBool(); |
Brian Salomon | f19f9ca | 2019-09-18 15:54:26 -0400 | [diff] [blame] | 1294 | auto saturate = random->nextBool() ? GrTextureOp::Saturate::kYes : GrTextureOp::Saturate::kNo; |
Greg Daniel | 549325c | 2019-10-30 16:19:20 -0400 | [diff] [blame] | 1295 | GrSurfaceProxyView proxyView( |
| 1296 | std::move(proxy), origin, |
Greg Daniel | 14b5721 | 2019-12-17 16:18:06 -0500 | [diff] [blame] | 1297 | context->priv().caps()->getReadSwizzle(format, GrColorType::kRGBA_8888)); |
Brian Salomon | fc11844 | 2019-11-22 19:09:27 -0500 | [diff] [blame] | 1298 | auto alphaType = static_cast<SkAlphaType>( |
| 1299 | random->nextRangeU(kUnknown_SkAlphaType + 1, kLastEnum_SkAlphaType)); |
Greg Daniel | 549325c | 2019-10-30 16:19:20 -0400 | [diff] [blame] | 1300 | |
Michael Ludwig | 6b45c5d | 2020-02-07 09:56:38 -0500 | [diff] [blame] | 1301 | DrawQuad quad = {GrQuad::MakeFromRect(rect, viewMatrix), GrQuad(srcRect), aaFlags}; |
Brian Salomon | fc11844 | 2019-11-22 19:09:27 -0500 | [diff] [blame] | 1302 | return GrTextureOp::Make(context, std::move(proxyView), alphaType, std::move(texXform), filter, |
Michael Ludwig | 6b45c5d | 2020-02-07 09:56:38 -0500 | [diff] [blame] | 1303 | color, saturate, SkBlendMode::kSrcOver, aaType, |
Brian Salomon | 2432d06 | 2020-04-16 20:48:09 -0400 | [diff] [blame^] | 1304 | &quad, useSubset ? &srcRect : nullptr); |
Brian Salomon | 3416969 | 2017-08-28 15:32:01 -0400 | [diff] [blame] | 1305 | } |
| 1306 | |
| 1307 | #endif |