blob: a1a2ea4ca3d5c59e9e66e71f2eab81bb2eb46320 [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -050013#include "include/core/SkTypes.h"
Mike Reed46f5c5f2020-02-20 15:42:29 -050014#include "include/core/SkM44.h"
Ethan Nicholas297d6ef2017-12-20 12:00:11 -050015
Mike Kleinc0bd9f92019-04-23 12:05:21 -050016#include "include/gpu/GrContext.h"
17#include "include/private/GrRecordingContext.h"
18#include "src/core/SkBlurPriv.h"
19#include "src/core/SkGpuBlurUtils.h"
20#include "src/core/SkRRectPriv.h"
21#include "src/gpu/GrCaps.h"
22#include "src/gpu/GrClip.h"
23#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"
28
29#include "src/gpu/GrCoordTransform.h"
30#include "src/gpu/GrFragmentProcessor.h"
Ethan Nicholas297d6ef2017-12-20 12:00:11 -050031class GrRRectBlurEffect : public GrFragmentProcessor {
32public:
Greg Daniel43956122020-02-11 15:49:27 -050033 static GrSurfaceProxyView find_or_create_rrect_blur_mask(GrRecordingContext* context,
34 const SkRRect& rrectToDraw,
35 const SkISize& dimensions,
36 float xformedSigma) {
Ethan Nicholas297d6ef2017-12-20 12:00:11 -050037 static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain();
Mike Kleind6ab77a2019-03-21 08:18:24 -050038 GrUniqueKey key;
39 GrUniqueKey::Builder builder(&key, kDomain, 9, "RoundRect Blur Mask");
Ethan Nicholas297d6ef2017-12-20 12:00:11 -050040 builder[0] = SkScalarCeilToInt(xformedSigma - 1 / 6.0f);
41
42 int index = 1;
Mike Kleind6ab77a2019-03-21 08:18:24 -050043 for (auto c : {SkRRect::kUpperLeft_Corner, SkRRect::kUpperRight_Corner,
44 SkRRect::kLowerRight_Corner, SkRRect::kLowerLeft_Corner}) {
Ethan Nicholas297d6ef2017-12-20 12:00:11 -050045 SkASSERT(SkScalarIsInt(rrectToDraw.radii(c).fX) &&
46 SkScalarIsInt(rrectToDraw.radii(c).fY));
47 builder[index++] = SkScalarCeilToInt(rrectToDraw.radii(c).fX);
48 builder[index++] = SkScalarCeilToInt(rrectToDraw.radii(c).fY);
49 }
50 builder.finish();
51
Brian Salomond005b692020-04-01 15:47:05 -040052 static constexpr auto kMaskOrigin = kBottomLeft_GrSurfaceOrigin;
Robert Phillips9da87e02019-02-04 13:26:26 -050053 GrProxyProvider* proxyProvider = context->priv().proxyProvider();
Robert Phillips1afd4cd2018-01-08 13:40:32 -050054
Brian Salomond005b692020-04-01 15:47:05 -040055 if (auto view = proxyProvider->findCachedProxyWithColorTypeFallback(
56 key, kMaskOrigin, GrColorType::kAlpha_8)) {
57 return view;
Ethan Nicholas297d6ef2017-12-20 12:00:11 -050058 }
59
Brian Salomond005b692020-04-01 15:47:05 -040060 auto rtc = GrRenderTargetContext::MakeWithFallback(
61 context, GrColorType::kAlpha_8, nullptr, SkBackingFit::kExact, dimensions, 1,
62 GrMipMapped::kNo, GrProtected::kNo, kMaskOrigin);
Greg Daniel43956122020-02-11 15:49:27 -050063 if (!rtc) {
64 return {};
65 }
66
67 GrPaint paint;
68
69 rtc->clear(nullptr, SK_PMColor4fTRANSPARENT,
70 GrRenderTargetContext::CanClearFullscreen::kYes);
71 rtc->drawRRect(GrNoClip(), std::move(paint), GrAA::kYes, SkMatrix::I(), rrectToDraw,
72 GrStyle::SimpleFill());
73
74 GrSurfaceProxyView srcView = rtc->readSurfaceView();
75 if (!srcView) {
76 return {};
77 }
78 SkASSERT(srcView.asTextureProxy());
79 auto rtc2 = SkGpuBlurUtils::GaussianBlur(context,
80 std::move(srcView),
81 rtc->colorInfo().colorType(),
82 rtc->colorInfo().alphaType(),
83 nullptr,
84 SkIRect::MakeSize(dimensions),
85 SkIRect::MakeSize(dimensions),
86 xformedSigma,
87 xformedSigma,
88 SkTileMode::kClamp,
89 SkBackingFit::kExact);
90 if (!rtc2) {
91 return {};
92 }
93
94 GrSurfaceProxyView mask = rtc2->readSurfaceView();
95 if (!mask) {
96 return {};
97 }
98 SkASSERT(mask.asTextureProxy());
99 SkASSERT(mask.origin() == kBottomLeft_GrSurfaceOrigin);
100 proxyProvider->assignUniqueKeyToProxy(key, mask.asTextureProxy());
101
Ethan Nicholas297d6ef2017-12-20 12:00:11 -0500102 return mask;
103 }
Ethan Nicholas297d6ef2017-12-20 12:00:11 -0500104
Robert Phillips7af8fe52019-02-14 17:27:00 -0500105 static std::unique_ptr<GrFragmentProcessor> Make(GrRecordingContext* context,
Mike Kleind6ab77a2019-03-21 08:18:24 -0500106 float sigma,
107 float xformedSigma,
108 const SkRRect& srcRRect,
109 const SkRRect& devRRect);
Ethan Nicholas297d6ef2017-12-20 12:00:11 -0500110 GrRRectBlurEffect(const GrRRectBlurEffect& src);
111 std::unique_ptr<GrFragmentProcessor> clone() const override;
Mike Kleind6ab77a2019-03-21 08:18:24 -0500112 const char* name() const override { return "RRectBlurEffect"; }
Ethan Nicholasbcd51e82019-04-09 10:40:41 -0400113 float sigma;
114 SkRect rect;
115 float cornerRadius;
116 TextureSampler ninePatchSampler;
Ethan Nicholas297d6ef2017-12-20 12:00:11 -0500117
118private:
Brian Osmanff0717f2020-03-27 11:08:38 -0400119 GrRRectBlurEffect(float sigma,
120 SkRect rect,
121 float cornerRadius,
Greg Daniel43956122020-02-11 15:49:27 -0500122 GrSurfaceProxyView ninePatchSampler)
Ethan Nicholas297d6ef2017-12-20 12:00:11 -0500123 : INHERITED(kGrRRectBlurEffect_ClassID,
124 (OptimizationFlags)kCompatibleWithCoverageAsAlpha_OptimizationFlag)
Ethan Nicholasbcd51e82019-04-09 10:40:41 -0400125 , sigma(sigma)
126 , rect(rect)
127 , cornerRadius(cornerRadius)
128 , ninePatchSampler(std::move(ninePatchSampler)) {
Brian Salomonf7dcd762018-07-30 14:48:15 -0400129 this->setTextureSamplerCnt(1);
Ethan Nicholas297d6ef2017-12-20 12:00:11 -0500130 }
131 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
132 void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
133 bool onIsEqual(const GrFragmentProcessor&) const override;
Brian Salomonf7dcd762018-07-30 14:48:15 -0400134 const TextureSampler& onTextureSampler(int) const override;
Ethan Nicholas297d6ef2017-12-20 12:00:11 -0500135 GR_DECLARE_FRAGMENT_PROCESSOR_TEST
Ethan Nicholas297d6ef2017-12-20 12:00:11 -0500136 typedef GrFragmentProcessor INHERITED;
137};
138#endif