blob: 1a28302a974b4d272a982da2734c56470e5ce916 [file] [log] [blame]
Ethan Nicholas297d6ef2017-12-20 12:00:11 -05001/*
Ethan Nicholas130fb3f2018-02-01 12:14:34 -05002 * Copyright 2018 Google Inc.
Ethan Nicholas297d6ef2017-12-20 12:00:11 -05003 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
Ethan Nicholas130fb3f2018-02-01 12:14:34 -05008/**************************************************************************************************
9 *** This file was autogenerated from GrRRectBlurEffect.fp; do not modify.
10 **************************************************************************************************/
Ethan Nicholas297d6ef2017-12-20 12:00:11 -050011#ifndef GrRRectBlurEffect_DEFINED
12#define GrRRectBlurEffect_DEFINED
John Stiles88183902020-06-10 16:40:38 -040013
Mike Reed46f5c5f2020-02-20 15:42:29 -050014#include "include/core/SkM44.h"
John Stiles88183902020-06-10 16:40:38 -040015#include "include/core/SkTypes.h"
Ethan Nicholas297d6ef2017-12-20 12:00:11 -050016
Mike Kleinc0bd9f92019-04-23 12:05:21 -050017#include "include/gpu/GrContext.h"
18#include "include/private/GrRecordingContext.h"
19#include "src/core/SkBlurPriv.h"
20#include "src/core/SkGpuBlurUtils.h"
21#include "src/core/SkRRectPriv.h"
22#include "src/gpu/GrCaps.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050023#include "src/gpu/GrPaint.h"
24#include "src/gpu/GrProxyProvider.h"
25#include "src/gpu/GrRecordingContextPriv.h"
26#include "src/gpu/GrRenderTargetContext.h"
27#include "src/gpu/GrStyle.h"
Brian Salomon99b04702020-06-18 10:12:47 -040028#include "src/gpu/effects/GrTextureEffect.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050029
30#include "src/gpu/GrCoordTransform.h"
31#include "src/gpu/GrFragmentProcessor.h"
John Stiles88183902020-06-10 16:40:38 -040032
Ethan Nicholas297d6ef2017-12-20 12:00:11 -050033class GrRRectBlurEffect : public GrFragmentProcessor {
34public:
Brian Salomon71f6cfd2020-06-17 17:14:12 -040035 static std::unique_ptr<GrFragmentProcessor> find_or_create_rrect_blur_mask_fp(
36 GrRecordingContext* context,
37 const SkRRect& rrectToDraw,
38 const SkISize& dimensions,
39 float xformedSigma) {
Ethan Nicholas297d6ef2017-12-20 12:00:11 -050040 static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain();
Mike Kleind6ab77a2019-03-21 08:18:24 -050041 GrUniqueKey key;
42 GrUniqueKey::Builder builder(&key, kDomain, 9, "RoundRect Blur Mask");
Ethan Nicholas297d6ef2017-12-20 12:00:11 -050043 builder[0] = SkScalarCeilToInt(xformedSigma - 1 / 6.0f);
44
45 int index = 1;
Mike Kleind6ab77a2019-03-21 08:18:24 -050046 for (auto c : {SkRRect::kUpperLeft_Corner, SkRRect::kUpperRight_Corner,
47 SkRRect::kLowerRight_Corner, SkRRect::kLowerLeft_Corner}) {
Ethan Nicholas297d6ef2017-12-20 12:00:11 -050048 SkASSERT(SkScalarIsInt(rrectToDraw.radii(c).fX) &&
49 SkScalarIsInt(rrectToDraw.radii(c).fY));
50 builder[index++] = SkScalarCeilToInt(rrectToDraw.radii(c).fX);
51 builder[index++] = SkScalarCeilToInt(rrectToDraw.radii(c).fY);
52 }
53 builder.finish();
54
Brian Salomon71f6cfd2020-06-17 17:14:12 -040055 // It seems like we could omit this matrix and modify the shader code to not normalize
56 // the coords used to sample the texture effect. However, the "proxyDims" value in the
57 // shader is not always the actual the proxy dimensions. This is because 'dimensions' here
58 // was computed using integer corner radii as determined in
59 // SkComputeBlurredRRectParams whereas the shader code uses the float radius to compute
60 // 'proxyDims'. Why it draws correctly with these unequal values is a mystery for the ages.
61 auto m = SkMatrix::Scale(dimensions.width(), dimensions.height());
Brian Salomond005b692020-04-01 15:47:05 -040062 static constexpr auto kMaskOrigin = kBottomLeft_GrSurfaceOrigin;
Robert Phillips9da87e02019-02-04 13:26:26 -050063 GrProxyProvider* proxyProvider = context->priv().proxyProvider();
Robert Phillips1afd4cd2018-01-08 13:40:32 -050064
Brian Salomond005b692020-04-01 15:47:05 -040065 if (auto view = proxyProvider->findCachedProxyWithColorTypeFallback(
Brian Salomon0029db02020-04-03 10:41:24 -040066 key, kMaskOrigin, GrColorType::kAlpha_8, 1)) {
Brian Salomon71f6cfd2020-06-17 17:14:12 -040067 return GrTextureEffect::Make(std::move(view), kPremul_SkAlphaType, m);
Ethan Nicholas297d6ef2017-12-20 12:00:11 -050068 }
69
Brian Salomond005b692020-04-01 15:47:05 -040070 auto rtc = GrRenderTargetContext::MakeWithFallback(
71 context, GrColorType::kAlpha_8, nullptr, SkBackingFit::kExact, dimensions, 1,
72 GrMipMapped::kNo, GrProtected::kNo, kMaskOrigin);
Greg Daniel43956122020-02-11 15:49:27 -050073 if (!rtc) {
Brian Salomon71f6cfd2020-06-17 17:14:12 -040074 return nullptr;
Greg Daniel43956122020-02-11 15:49:27 -050075 }
76
77 GrPaint paint;
78
Michael Ludwig81d41722020-05-26 16:57:38 -040079 rtc->clear(SK_PMColor4fTRANSPARENT);
Michael Ludwig7c12e282020-05-29 09:54:07 -040080 rtc->drawRRect(nullptr, std::move(paint), GrAA::kYes, SkMatrix::I(), rrectToDraw,
Greg Daniel43956122020-02-11 15:49:27 -050081 GrStyle::SimpleFill());
82
83 GrSurfaceProxyView srcView = rtc->readSurfaceView();
84 if (!srcView) {
Brian Salomon71f6cfd2020-06-17 17:14:12 -040085 return nullptr;
Greg Daniel43956122020-02-11 15:49:27 -050086 }
87 SkASSERT(srcView.asTextureProxy());
88 auto rtc2 = SkGpuBlurUtils::GaussianBlur(context,
89 std::move(srcView),
90 rtc->colorInfo().colorType(),
91 rtc->colorInfo().alphaType(),
92 nullptr,
93 SkIRect::MakeSize(dimensions),
94 SkIRect::MakeSize(dimensions),
95 xformedSigma,
96 xformedSigma,
97 SkTileMode::kClamp,
98 SkBackingFit::kExact);
99 if (!rtc2) {
Brian Salomon71f6cfd2020-06-17 17:14:12 -0400100 return nullptr;
Greg Daniel43956122020-02-11 15:49:27 -0500101 }
102
103 GrSurfaceProxyView mask = rtc2->readSurfaceView();
104 if (!mask) {
Brian Salomon71f6cfd2020-06-17 17:14:12 -0400105 return nullptr;
Greg Daniel43956122020-02-11 15:49:27 -0500106 }
107 SkASSERT(mask.asTextureProxy());
Brian Salomon11ad4cc2020-05-15 12:07:59 -0400108 SkASSERT(mask.origin() == kMaskOrigin);
Greg Daniel43956122020-02-11 15:49:27 -0500109 proxyProvider->assignUniqueKeyToProxy(key, mask.asTextureProxy());
Brian Salomon71f6cfd2020-06-17 17:14:12 -0400110 return GrTextureEffect::Make(std::move(mask), kPremul_SkAlphaType, m);
Ethan Nicholas297d6ef2017-12-20 12:00:11 -0500111 }
Ethan Nicholas297d6ef2017-12-20 12:00:11 -0500112
John Stiles4ca88842020-06-08 17:20:01 -0400113 static std::unique_ptr<GrFragmentProcessor> Make(std::unique_ptr<GrFragmentProcessor> inputFP,
114 GrRecordingContext* context,
Mike Kleind6ab77a2019-03-21 08:18:24 -0500115 float sigma,
116 float xformedSigma,
117 const SkRRect& srcRRect,
118 const SkRRect& devRRect);
Ethan Nicholas297d6ef2017-12-20 12:00:11 -0500119 GrRRectBlurEffect(const GrRRectBlurEffect& src);
120 std::unique_ptr<GrFragmentProcessor> clone() const override;
Mike Kleind6ab77a2019-03-21 08:18:24 -0500121 const char* name() const override { return "RRectBlurEffect"; }
John Stiles4ca88842020-06-08 17:20:01 -0400122 int inputFP_index = -1;
Ethan Nicholasbcd51e82019-04-09 10:40:41 -0400123 float sigma;
124 SkRect rect;
125 float cornerRadius;
Brian Salomon71f6cfd2020-06-17 17:14:12 -0400126 int ninePatchFP_index = -1;
Ethan Nicholas297d6ef2017-12-20 12:00:11 -0500127
128private:
John Stiles4ca88842020-06-08 17:20:01 -0400129 GrRRectBlurEffect(std::unique_ptr<GrFragmentProcessor> inputFP,
130 float sigma,
Brian Osmanff0717f2020-03-27 11:08:38 -0400131 SkRect rect,
132 float cornerRadius,
Brian Salomon71f6cfd2020-06-17 17:14:12 -0400133 std::unique_ptr<GrFragmentProcessor> ninePatchFP)
Ethan Nicholas297d6ef2017-12-20 12:00:11 -0500134 : INHERITED(kGrRRectBlurEffect_ClassID,
John Stiles4ca88842020-06-08 17:20:01 -0400135 (OptimizationFlags)(inputFP ? ProcessorOptimizationFlags(inputFP.get())
136 : kAll_OptimizationFlags) &
137 kCompatibleWithCoverageAsAlpha_OptimizationFlag)
Ethan Nicholasbcd51e82019-04-09 10:40:41 -0400138 , sigma(sigma)
139 , rect(rect)
Brian Salomon71f6cfd2020-06-17 17:14:12 -0400140 , cornerRadius(cornerRadius) {
John Stiles4ca88842020-06-08 17:20:01 -0400141 if (inputFP) {
John Stiles88183902020-06-10 16:40:38 -0400142 inputFP_index = this->registerChildProcessor(std::move(inputFP));
John Stiles4ca88842020-06-08 17:20:01 -0400143 }
Brian Salomon71f6cfd2020-06-17 17:14:12 -0400144 SkASSERT(ninePatchFP);
145 ninePatchFP->setSampledWithExplicitCoords();
146 ninePatchFP_index = this->registerChildProcessor(std::move(ninePatchFP));
Ethan Nicholas297d6ef2017-12-20 12:00:11 -0500147 }
148 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
149 void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
150 bool onIsEqual(const GrFragmentProcessor&) const override;
151 GR_DECLARE_FRAGMENT_PROCESSOR_TEST
Ethan Nicholas297d6ef2017-12-20 12:00:11 -0500152 typedef GrFragmentProcessor INHERITED;
153};
154#endif