blob: 7c8d74841f3696b2644594f0cf5f30037390d767 [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 Reedb26b4e72020-01-22 14:31:21 -050014#include "include/private/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:
Robert Phillips7af8fe52019-02-14 17:27:00 -050033 static sk_sp<GrTextureProxy> find_or_create_rrect_blur_mask(GrRecordingContext* context,
Mike Kleind6ab77a2019-03-21 08:18:24 -050034 const SkRRect& rrectToDraw,
Brian Salomon9f2b86c2019-10-22 10:37:46 -040035 const SkISize& dimensions,
Mike Kleind6ab77a2019-03-21 08:18:24 -050036 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
Robert Phillips9da87e02019-02-04 13:26:26 -050052 GrProxyProvider* proxyProvider = context->priv().proxyProvider();
Robert Phillips1afd4cd2018-01-08 13:40:32 -050053
Brian Salomon2af3e702019-08-11 19:10:31 -040054 sk_sp<GrTextureProxy> mask(proxyProvider->findOrCreateProxyByUniqueKey(
55 key, GrColorType::kAlpha_8, kBottomLeft_GrSurfaceOrigin));
Ethan Nicholas297d6ef2017-12-20 12:00:11 -050056 if (!mask) {
Greg Daniele20fcad2020-01-08 11:52:34 -050057 auto rtc = GrRenderTargetContext::MakeWithFallback(
Brian Salomon37e7b362020-01-29 12:42:07 -050058 context, GrColorType::kAlpha_8, nullptr, SkBackingFit::kExact, dimensions);
Ethan Nicholas297d6ef2017-12-20 12:00:11 -050059 if (!rtc) {
60 return nullptr;
61 }
62
63 GrPaint paint;
64
Mike Kleind6ab77a2019-03-21 08:18:24 -050065 rtc->clear(nullptr, SK_PMColor4fTRANSPARENT,
Brian Osman9a9baae2018-11-05 15:06:26 -050066 GrRenderTargetContext::CanClearFullscreen::kYes);
Mike Kleind6ab77a2019-03-21 08:18:24 -050067 rtc->drawRRect(GrNoClip(), std::move(paint), GrAA::kYes, SkMatrix::I(), rrectToDraw,
Ethan Nicholas297d6ef2017-12-20 12:00:11 -050068 GrStyle::SimpleFill());
69
Greg Daniel5c082492020-01-29 15:06:49 -050070 GrSurfaceProxyView srcView = rtc->readSurfaceView();
71 if (!srcView.asTextureProxy()) {
Ethan Nicholas297d6ef2017-12-20 12:00:11 -050072 return nullptr;
73 }
Brian Salomonbf6b9792019-08-21 09:38:10 -040074 auto rtc2 = SkGpuBlurUtils::GaussianBlur(context,
Greg Daniel5c082492020-01-29 15:06:49 -050075 std::move(srcView),
Brian Salomon4bc0c1f2019-09-30 15:12:27 -040076 rtc->colorInfo().colorType(),
77 rtc->colorInfo().alphaType(),
Brian Salomonbf6b9792019-08-21 09:38:10 -040078 nullptr,
Brian Salomon9f2b86c2019-10-22 10:37:46 -040079 SkIRect::MakeSize(dimensions),
Brian Salomonfba4a152020-01-16 15:46:06 -050080 SkIRect::MakeSize(dimensions),
Brian Salomonbf6b9792019-08-21 09:38:10 -040081 xformedSigma,
82 xformedSigma,
Brian Salomonf631cf32020-01-16 17:18:46 -050083 SkTileMode::kClamp,
Brian Salomonbf6b9792019-08-21 09:38:10 -040084 SkBackingFit::kExact);
Ethan Nicholas297d6ef2017-12-20 12:00:11 -050085 if (!rtc2) {
86 return nullptr;
87 }
88
89 mask = rtc2->asTextureProxyRef();
90 if (!mask) {
91 return nullptr;
92 }
93 SkASSERT(mask->origin() == kBottomLeft_GrSurfaceOrigin);
Robert Phillips1afd4cd2018-01-08 13:40:32 -050094 proxyProvider->assignUniqueKeyToProxy(key, mask.get());
Ethan Nicholas297d6ef2017-12-20 12:00:11 -050095 }
96
97 return mask;
98 }
Ethan Nicholas297d6ef2017-12-20 12:00:11 -050099
Robert Phillips7af8fe52019-02-14 17:27:00 -0500100 static std::unique_ptr<GrFragmentProcessor> Make(GrRecordingContext* context,
Mike Kleind6ab77a2019-03-21 08:18:24 -0500101 float sigma,
102 float xformedSigma,
103 const SkRRect& srcRRect,
104 const SkRRect& devRRect);
Ethan Nicholas297d6ef2017-12-20 12:00:11 -0500105 GrRRectBlurEffect(const GrRRectBlurEffect& src);
106 std::unique_ptr<GrFragmentProcessor> clone() const override;
Mike Kleind6ab77a2019-03-21 08:18:24 -0500107 const char* name() const override { return "RRectBlurEffect"; }
Ethan Nicholasbcd51e82019-04-09 10:40:41 -0400108 float sigma;
109 SkRect rect;
110 float cornerRadius;
111 TextureSampler ninePatchSampler;
Ethan Nicholas297d6ef2017-12-20 12:00:11 -0500112
113private:
Mike Kleind6ab77a2019-03-21 08:18:24 -0500114 GrRRectBlurEffect(float sigma, SkRect rect, float cornerRadius,
Michael Ludwig8fa469d2019-11-25 16:08:44 -0500115 sk_sp<GrSurfaceProxy> ninePatchSampler)
Ethan Nicholas297d6ef2017-12-20 12:00:11 -0500116 : INHERITED(kGrRRectBlurEffect_ClassID,
117 (OptimizationFlags)kCompatibleWithCoverageAsAlpha_OptimizationFlag)
Ethan Nicholasbcd51e82019-04-09 10:40:41 -0400118 , sigma(sigma)
119 , rect(rect)
120 , cornerRadius(cornerRadius)
121 , ninePatchSampler(std::move(ninePatchSampler)) {
Brian Salomonf7dcd762018-07-30 14:48:15 -0400122 this->setTextureSamplerCnt(1);
Ethan Nicholas297d6ef2017-12-20 12:00:11 -0500123 }
124 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
125 void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
126 bool onIsEqual(const GrFragmentProcessor&) const override;
Brian Salomonf7dcd762018-07-30 14:48:15 -0400127 const TextureSampler& onTextureSampler(int) const override;
Ethan Nicholas297d6ef2017-12-20 12:00:11 -0500128 GR_DECLARE_FRAGMENT_PROCESSOR_TEST
Ethan Nicholas297d6ef2017-12-20 12:00:11 -0500129 typedef GrFragmentProcessor INHERITED;
130};
131#endif