blob: 8b4848978b22a90b0fc165436bff59216f2f268a [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"
Ethan Nicholas297d6ef2017-12-20 12:00:11 -050014
Mike Kleinc0bd9f92019-04-23 12:05:21 -050015#include "include/effects/SkBlurMaskFilter.h"
16#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,
35 const SkISize& size,
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
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) {
Chris Daltonb618b772019-09-18 15:45:19 +000057 // TODO: this could be approx but the texture coords will need to be updated
Brian Salomonbf6b9792019-08-21 09:38:10 -040058 auto rtc = context->priv().makeDeferredRenderTargetContextWithFallback(
59 SkBackingFit::kExact, size.fWidth, size.fHeight, GrColorType::kAlpha_8,
60 nullptr);
Ethan Nicholas297d6ef2017-12-20 12:00:11 -050061 if (!rtc) {
62 return nullptr;
63 }
64
65 GrPaint paint;
66
Mike Kleind6ab77a2019-03-21 08:18:24 -050067 rtc->clear(nullptr, SK_PMColor4fTRANSPARENT,
Brian Osman9a9baae2018-11-05 15:06:26 -050068 GrRenderTargetContext::CanClearFullscreen::kYes);
Mike Kleind6ab77a2019-03-21 08:18:24 -050069 rtc->drawRRect(GrNoClip(), std::move(paint), GrAA::kYes, SkMatrix::I(), rrectToDraw,
Ethan Nicholas297d6ef2017-12-20 12:00:11 -050070 GrStyle::SimpleFill());
71
72 sk_sp<GrTextureProxy> srcProxy(rtc->asTextureProxyRef());
73 if (!srcProxy) {
74 return nullptr;
75 }
Brian Salomonbf6b9792019-08-21 09:38:10 -040076 auto rtc2 = SkGpuBlurUtils::GaussianBlur(context,
77 std::move(srcProxy),
Robert Phillipsf5807212019-09-18 13:30:24 -040078 GrColorType::kAlpha_8,
79 kPremul_SkAlphaType,
Brian Salomonbf6b9792019-08-21 09:38:10 -040080 SkIPoint::Make(0, 0),
81 nullptr,
82 SkIRect::MakeWH(size.fWidth, size.fHeight),
83 SkIRect::EmptyIRect(),
84 xformedSigma,
85 xformedSigma,
86 GrTextureDomain::kIgnore_Mode,
Brian Salomonbf6b9792019-08-21 09:38:10 -040087 SkBackingFit::kExact);
Ethan Nicholas297d6ef2017-12-20 12:00:11 -050088 if (!rtc2) {
89 return nullptr;
90 }
91
92 mask = rtc2->asTextureProxyRef();
93 if (!mask) {
94 return nullptr;
95 }
96 SkASSERT(mask->origin() == kBottomLeft_GrSurfaceOrigin);
Robert Phillips1afd4cd2018-01-08 13:40:32 -050097 proxyProvider->assignUniqueKeyToProxy(key, mask.get());
Ethan Nicholas297d6ef2017-12-20 12:00:11 -050098 }
99
100 return mask;
101 }
Ethan Nicholas297d6ef2017-12-20 12:00:11 -0500102
Robert Phillips7af8fe52019-02-14 17:27:00 -0500103 static std::unique_ptr<GrFragmentProcessor> Make(GrRecordingContext* context,
Mike Kleind6ab77a2019-03-21 08:18:24 -0500104 float sigma,
105 float xformedSigma,
106 const SkRRect& srcRRect,
107 const SkRRect& devRRect);
Ethan Nicholas297d6ef2017-12-20 12:00:11 -0500108 GrRRectBlurEffect(const GrRRectBlurEffect& src);
109 std::unique_ptr<GrFragmentProcessor> clone() const override;
Mike Kleind6ab77a2019-03-21 08:18:24 -0500110 const char* name() const override { return "RRectBlurEffect"; }
Ethan Nicholasbcd51e82019-04-09 10:40:41 -0400111 float sigma;
112 SkRect rect;
113 float cornerRadius;
114 TextureSampler ninePatchSampler;
Ethan Nicholas297d6ef2017-12-20 12:00:11 -0500115
116private:
Mike Kleind6ab77a2019-03-21 08:18:24 -0500117 GrRRectBlurEffect(float sigma, SkRect rect, float cornerRadius,
Ethan Nicholas297d6ef2017-12-20 12:00:11 -0500118 sk_sp<GrTextureProxy> ninePatchSampler)
119 : INHERITED(kGrRRectBlurEffect_ClassID,
120 (OptimizationFlags)kCompatibleWithCoverageAsAlpha_OptimizationFlag)
Ethan Nicholasbcd51e82019-04-09 10:40:41 -0400121 , sigma(sigma)
122 , rect(rect)
123 , cornerRadius(cornerRadius)
124 , ninePatchSampler(std::move(ninePatchSampler)) {
Brian Salomonf7dcd762018-07-30 14:48:15 -0400125 this->setTextureSamplerCnt(1);
Ethan Nicholas297d6ef2017-12-20 12:00:11 -0500126 }
127 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
128 void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
129 bool onIsEqual(const GrFragmentProcessor&) const override;
Brian Salomonf7dcd762018-07-30 14:48:15 -0400130 const TextureSampler& onTextureSampler(int) const override;
Ethan Nicholas297d6ef2017-12-20 12:00:11 -0500131 GR_DECLARE_FRAGMENT_PROCESSOR_TEST
Ethan Nicholas297d6ef2017-12-20 12:00:11 -0500132 typedef GrFragmentProcessor INHERITED;
133};
134#endif