blob: 25037d6ea02f2e1233f1f2b6bf99a20c50c3fca8 [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"
Robert Phillipsb7bfbc22020-07-01 12:55:01 -040018#include "include/gpu/GrRecordingContext.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050019#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
Mike Kleinc0bd9f92019-04-23 12:05:21 -050030#include "src/gpu/GrFragmentProcessor.h"
John Stiles88183902020-06-10 16:40:38 -040031
Ethan Nicholas297d6ef2017-12-20 12:00:11 -050032class GrRRectBlurEffect : public GrFragmentProcessor {
33public:
Brian Salomon71f6cfd2020-06-17 17:14:12 -040034 static std::unique_ptr<GrFragmentProcessor> find_or_create_rrect_blur_mask_fp(
35 GrRecordingContext* context,
36 const SkRRect& rrectToDraw,
37 const SkISize& dimensions,
38 float xformedSigma) {
Ethan Nicholas297d6ef2017-12-20 12:00:11 -050039 static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain();
Mike Kleind6ab77a2019-03-21 08:18:24 -050040 GrUniqueKey key;
41 GrUniqueKey::Builder builder(&key, kDomain, 9, "RoundRect Blur Mask");
Ethan Nicholas297d6ef2017-12-20 12:00:11 -050042 builder[0] = SkScalarCeilToInt(xformedSigma - 1 / 6.0f);
43
44 int index = 1;
Mike Kleind6ab77a2019-03-21 08:18:24 -050045 for (auto c : {SkRRect::kUpperLeft_Corner, SkRRect::kUpperRight_Corner,
46 SkRRect::kLowerRight_Corner, SkRRect::kLowerLeft_Corner}) {
Ethan Nicholas297d6ef2017-12-20 12:00:11 -050047 SkASSERT(SkScalarIsInt(rrectToDraw.radii(c).fX) &&
48 SkScalarIsInt(rrectToDraw.radii(c).fY));
49 builder[index++] = SkScalarCeilToInt(rrectToDraw.radii(c).fX);
50 builder[index++] = SkScalarCeilToInt(rrectToDraw.radii(c).fY);
51 }
52 builder.finish();
53
Brian Salomon71f6cfd2020-06-17 17:14:12 -040054 // It seems like we could omit this matrix and modify the shader code to not normalize
55 // the coords used to sample the texture effect. However, the "proxyDims" value in the
56 // shader is not always the actual the proxy dimensions. This is because 'dimensions' here
57 // was computed using integer corner radii as determined in
58 // SkComputeBlurredRRectParams whereas the shader code uses the float radius to compute
59 // 'proxyDims'. Why it draws correctly with these unequal values is a mystery for the ages.
60 auto m = SkMatrix::Scale(dimensions.width(), dimensions.height());
Brian Salomond005b692020-04-01 15:47:05 -040061 static constexpr auto kMaskOrigin = kBottomLeft_GrSurfaceOrigin;
Robert Phillips9da87e02019-02-04 13:26:26 -050062 GrProxyProvider* proxyProvider = context->priv().proxyProvider();
Robert Phillips1afd4cd2018-01-08 13:40:32 -050063
Brian Salomond005b692020-04-01 15:47:05 -040064 if (auto view = proxyProvider->findCachedProxyWithColorTypeFallback(
Brian Salomon0029db02020-04-03 10:41:24 -040065 key, kMaskOrigin, GrColorType::kAlpha_8, 1)) {
Brian Salomon71f6cfd2020-06-17 17:14:12 -040066 return GrTextureEffect::Make(std::move(view), kPremul_SkAlphaType, m);
Ethan Nicholas297d6ef2017-12-20 12:00:11 -050067 }
68
Brian Salomond005b692020-04-01 15:47:05 -040069 auto rtc = GrRenderTargetContext::MakeWithFallback(
70 context, GrColorType::kAlpha_8, nullptr, SkBackingFit::kExact, dimensions, 1,
71 GrMipMapped::kNo, GrProtected::kNo, kMaskOrigin);
Greg Daniel43956122020-02-11 15:49:27 -050072 if (!rtc) {
Brian Salomon71f6cfd2020-06-17 17:14:12 -040073 return nullptr;
Greg Daniel43956122020-02-11 15:49:27 -050074 }
75
76 GrPaint paint;
77
Michael Ludwig81d41722020-05-26 16:57:38 -040078 rtc->clear(SK_PMColor4fTRANSPARENT);
Michael Ludwig7c12e282020-05-29 09:54:07 -040079 rtc->drawRRect(nullptr, std::move(paint), GrAA::kYes, SkMatrix::I(), rrectToDraw,
Greg Daniel43956122020-02-11 15:49:27 -050080 GrStyle::SimpleFill());
81
82 GrSurfaceProxyView srcView = rtc->readSurfaceView();
83 if (!srcView) {
Brian Salomon71f6cfd2020-06-17 17:14:12 -040084 return nullptr;
Greg Daniel43956122020-02-11 15:49:27 -050085 }
86 SkASSERT(srcView.asTextureProxy());
87 auto rtc2 = SkGpuBlurUtils::GaussianBlur(context,
88 std::move(srcView),
89 rtc->colorInfo().colorType(),
90 rtc->colorInfo().alphaType(),
91 nullptr,
92 SkIRect::MakeSize(dimensions),
93 SkIRect::MakeSize(dimensions),
94 xformedSigma,
95 xformedSigma,
96 SkTileMode::kClamp,
97 SkBackingFit::kExact);
98 if (!rtc2) {
Brian Salomon71f6cfd2020-06-17 17:14:12 -040099 return nullptr;
Greg Daniel43956122020-02-11 15:49:27 -0500100 }
101
102 GrSurfaceProxyView mask = rtc2->readSurfaceView();
103 if (!mask) {
Brian Salomon71f6cfd2020-06-17 17:14:12 -0400104 return nullptr;
Greg Daniel43956122020-02-11 15:49:27 -0500105 }
106 SkASSERT(mask.asTextureProxy());
Brian Salomon11ad4cc2020-05-15 12:07:59 -0400107 SkASSERT(mask.origin() == kMaskOrigin);
Greg Daniel43956122020-02-11 15:49:27 -0500108 proxyProvider->assignUniqueKeyToProxy(key, mask.asTextureProxy());
Brian Salomon71f6cfd2020-06-17 17:14:12 -0400109 return GrTextureEffect::Make(std::move(mask), kPremul_SkAlphaType, m);
Ethan Nicholas297d6ef2017-12-20 12:00:11 -0500110 }
Ethan Nicholas297d6ef2017-12-20 12:00:11 -0500111
John Stiles4ca88842020-06-08 17:20:01 -0400112 static std::unique_ptr<GrFragmentProcessor> Make(std::unique_ptr<GrFragmentProcessor> inputFP,
113 GrRecordingContext* context,
Mike Kleind6ab77a2019-03-21 08:18:24 -0500114 float sigma,
115 float xformedSigma,
116 const SkRRect& srcRRect,
117 const SkRRect& devRRect);
Ethan Nicholas297d6ef2017-12-20 12:00:11 -0500118 GrRRectBlurEffect(const GrRRectBlurEffect& src);
119 std::unique_ptr<GrFragmentProcessor> clone() const override;
Mike Kleind6ab77a2019-03-21 08:18:24 -0500120 const char* name() const override { return "RRectBlurEffect"; }
John Stiles4ca88842020-06-08 17:20:01 -0400121 int inputFP_index = -1;
Ethan Nicholasbcd51e82019-04-09 10:40:41 -0400122 float sigma;
123 SkRect rect;
124 float cornerRadius;
Brian Salomon71f6cfd2020-06-17 17:14:12 -0400125 int ninePatchFP_index = -1;
Ethan Nicholas297d6ef2017-12-20 12:00:11 -0500126
127private:
John Stiles4ca88842020-06-08 17:20:01 -0400128 GrRRectBlurEffect(std::unique_ptr<GrFragmentProcessor> inputFP,
129 float sigma,
Brian Osmanff0717f2020-03-27 11:08:38 -0400130 SkRect rect,
131 float cornerRadius,
Brian Salomon71f6cfd2020-06-17 17:14:12 -0400132 std::unique_ptr<GrFragmentProcessor> ninePatchFP)
Ethan Nicholas297d6ef2017-12-20 12:00:11 -0500133 : INHERITED(kGrRRectBlurEffect_ClassID,
John Stiles4ca88842020-06-08 17:20:01 -0400134 (OptimizationFlags)(inputFP ? ProcessorOptimizationFlags(inputFP.get())
135 : kAll_OptimizationFlags) &
136 kCompatibleWithCoverageAsAlpha_OptimizationFlag)
Ethan Nicholasbcd51e82019-04-09 10:40:41 -0400137 , sigma(sigma)
138 , rect(rect)
Brian Salomon71f6cfd2020-06-17 17:14:12 -0400139 , cornerRadius(cornerRadius) {
John Stiles4ca88842020-06-08 17:20:01 -0400140 if (inputFP) {
Brian Osman1298bc42020-06-30 13:39:35 -0400141 inputFP_index =
142 this->registerChild(std::move(inputFP), SkSL::SampleUsage::PassThrough());
John Stiles4ca88842020-06-08 17:20:01 -0400143 }
Brian Salomon71f6cfd2020-06-17 17:14:12 -0400144 SkASSERT(ninePatchFP);
Brian Osman1298bc42020-06-30 13:39:35 -0400145 ninePatchFP_index =
146 this->registerChild(std::move(ninePatchFP), SkSL::SampleUsage::Explicit());
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