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