blob: 5238abb8df9f34a8f3ce025f5ee0bd75e7652fd0 [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/gpu/GrContext.h"
16#include "include/private/GrRecordingContext.h"
17#include "src/core/SkBlurPriv.h"
18#include "src/core/SkGpuBlurUtils.h"
19#include "src/core/SkRRectPriv.h"
20#include "src/gpu/GrCaps.h"
21#include "src/gpu/GrClip.h"
22#include "src/gpu/GrPaint.h"
23#include "src/gpu/GrProxyProvider.h"
24#include "src/gpu/GrRecordingContextPriv.h"
25#include "src/gpu/GrRenderTargetContext.h"
26#include "src/gpu/GrStyle.h"
27
28#include "src/gpu/GrCoordTransform.h"
29#include "src/gpu/GrFragmentProcessor.h"
Ethan Nicholas297d6ef2017-12-20 12:00:11 -050030class GrRRectBlurEffect : public GrFragmentProcessor {
31public:
Robert Phillips7af8fe52019-02-14 17:27:00 -050032 static sk_sp<GrTextureProxy> find_or_create_rrect_blur_mask(GrRecordingContext* context,
Mike Kleind6ab77a2019-03-21 08:18:24 -050033 const SkRRect& rrectToDraw,
Brian Salomon9f2b86c2019-10-22 10:37:46 -040034 const SkISize& dimensions,
Mike Kleind6ab77a2019-03-21 08:18:24 -050035 float xformedSigma) {
Ethan Nicholas297d6ef2017-12-20 12:00:11 -050036 static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain();
Mike Kleind6ab77a2019-03-21 08:18:24 -050037 GrUniqueKey key;
38 GrUniqueKey::Builder builder(&key, kDomain, 9, "RoundRect Blur Mask");
Ethan Nicholas297d6ef2017-12-20 12:00:11 -050039 builder[0] = SkScalarCeilToInt(xformedSigma - 1 / 6.0f);
40
41 int index = 1;
Mike Kleind6ab77a2019-03-21 08:18:24 -050042 for (auto c : {SkRRect::kUpperLeft_Corner, SkRRect::kUpperRight_Corner,
43 SkRRect::kLowerRight_Corner, SkRRect::kLowerLeft_Corner}) {
Ethan Nicholas297d6ef2017-12-20 12:00:11 -050044 SkASSERT(SkScalarIsInt(rrectToDraw.radii(c).fX) &&
45 SkScalarIsInt(rrectToDraw.radii(c).fY));
46 builder[index++] = SkScalarCeilToInt(rrectToDraw.radii(c).fX);
47 builder[index++] = SkScalarCeilToInt(rrectToDraw.radii(c).fY);
48 }
49 builder.finish();
50
Robert Phillips9da87e02019-02-04 13:26:26 -050051 GrProxyProvider* proxyProvider = context->priv().proxyProvider();
Robert Phillips1afd4cd2018-01-08 13:40:32 -050052
Brian Salomon2af3e702019-08-11 19:10:31 -040053 sk_sp<GrTextureProxy> mask(proxyProvider->findOrCreateProxyByUniqueKey(
54 key, GrColorType::kAlpha_8, kBottomLeft_GrSurfaceOrigin));
Ethan Nicholas297d6ef2017-12-20 12:00:11 -050055 if (!mask) {
Chris Dalton0493fbd2019-09-18 15:49:46 -060056 // TODO: this could be SkBackingFit::kApprox, but:
57 // 1) The texture coords would need to be updated.
58 // 2) We would have to use GrTextureDomain::kClamp_Mode for the GaussianBlur.
Brian Salomonbf6b9792019-08-21 09:38:10 -040059 auto rtc = context->priv().makeDeferredRenderTargetContextWithFallback(
Brian Salomon9f2b86c2019-10-22 10:37:46 -040060 SkBackingFit::kExact, dimensions.fWidth, dimensions.fHeight,
61 GrColorType::kAlpha_8, nullptr);
Ethan Nicholas297d6ef2017-12-20 12:00:11 -050062 if (!rtc) {
63 return nullptr;
64 }
65
66 GrPaint paint;
67
Mike Kleind6ab77a2019-03-21 08:18:24 -050068 rtc->clear(nullptr, SK_PMColor4fTRANSPARENT,
Brian Osman9a9baae2018-11-05 15:06:26 -050069 GrRenderTargetContext::CanClearFullscreen::kYes);
Mike Kleind6ab77a2019-03-21 08:18:24 -050070 rtc->drawRRect(GrNoClip(), std::move(paint), GrAA::kYes, SkMatrix::I(), rrectToDraw,
Ethan Nicholas297d6ef2017-12-20 12:00:11 -050071 GrStyle::SimpleFill());
72
73 sk_sp<GrTextureProxy> srcProxy(rtc->asTextureProxyRef());
74 if (!srcProxy) {
75 return nullptr;
76 }
Brian Salomonbf6b9792019-08-21 09:38:10 -040077 auto rtc2 = SkGpuBlurUtils::GaussianBlur(context,
78 std::move(srcProxy),
Brian Salomon4bc0c1f2019-09-30 15:12:27 -040079 rtc->colorInfo().colorType(),
80 rtc->colorInfo().alphaType(),
Brian Salomonbf6b9792019-08-21 09:38:10 -040081 SkIPoint::Make(0, 0),
82 nullptr,
Brian Salomon9f2b86c2019-10-22 10:37:46 -040083 SkIRect::MakeSize(dimensions),
Brian Salomon44207f32020-01-06 15:20:18 -050084 SkIRect::MakeEmpty(),
Brian Salomonbf6b9792019-08-21 09:38:10 -040085 xformedSigma,
86 xformedSigma,
87 GrTextureDomain::kIgnore_Mode,
Brian Salomonbf6b9792019-08-21 09:38:10 -040088 SkBackingFit::kExact);
Ethan Nicholas297d6ef2017-12-20 12:00:11 -050089 if (!rtc2) {
90 return nullptr;
91 }
92
93 mask = rtc2->asTextureProxyRef();
94 if (!mask) {
95 return nullptr;
96 }
97 SkASSERT(mask->origin() == kBottomLeft_GrSurfaceOrigin);
Robert Phillips1afd4cd2018-01-08 13:40:32 -050098 proxyProvider->assignUniqueKeyToProxy(key, mask.get());
Ethan Nicholas297d6ef2017-12-20 12:00:11 -050099 }
100
101 return mask;
102 }
Ethan Nicholas297d6ef2017-12-20 12:00:11 -0500103
Robert Phillips7af8fe52019-02-14 17:27:00 -0500104 static std::unique_ptr<GrFragmentProcessor> Make(GrRecordingContext* context,
Mike Kleind6ab77a2019-03-21 08:18:24 -0500105 float sigma,
106 float xformedSigma,
107 const SkRRect& srcRRect,
108 const SkRRect& devRRect);
Ethan Nicholas297d6ef2017-12-20 12:00:11 -0500109 GrRRectBlurEffect(const GrRRectBlurEffect& src);
110 std::unique_ptr<GrFragmentProcessor> clone() const override;
Mike Kleind6ab77a2019-03-21 08:18:24 -0500111 const char* name() const override { return "RRectBlurEffect"; }
Ethan Nicholasbcd51e82019-04-09 10:40:41 -0400112 float sigma;
113 SkRect rect;
114 float cornerRadius;
115 TextureSampler ninePatchSampler;
Ethan Nicholas297d6ef2017-12-20 12:00:11 -0500116
117private:
Mike Kleind6ab77a2019-03-21 08:18:24 -0500118 GrRRectBlurEffect(float sigma, SkRect rect, float cornerRadius,
Michael Ludwig8fa469d2019-11-25 16:08:44 -0500119 sk_sp<GrSurfaceProxy> ninePatchSampler)
Ethan Nicholas297d6ef2017-12-20 12:00:11 -0500120 : INHERITED(kGrRRectBlurEffect_ClassID,
121 (OptimizationFlags)kCompatibleWithCoverageAsAlpha_OptimizationFlag)
Ethan Nicholasbcd51e82019-04-09 10:40:41 -0400122 , sigma(sigma)
123 , rect(rect)
124 , cornerRadius(cornerRadius)
125 , ninePatchSampler(std::move(ninePatchSampler)) {
Brian Salomonf7dcd762018-07-30 14:48:15 -0400126 this->setTextureSamplerCnt(1);
Ethan Nicholas297d6ef2017-12-20 12:00:11 -0500127 }
128 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
129 void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
130 bool onIsEqual(const GrFragmentProcessor&) const override;
Brian Salomonf7dcd762018-07-30 14:48:15 -0400131 const TextureSampler& onTextureSampler(int) const override;
Ethan Nicholas297d6ef2017-12-20 12:00:11 -0500132 GR_DECLARE_FRAGMENT_PROCESSOR_TEST
Ethan Nicholas297d6ef2017-12-20 12:00:11 -0500133 typedef GrFragmentProcessor INHERITED;
134};
135#endif