Flutter Engine
The Flutter Engine
Functions
skgpu::ganesh::ShadowRRectOp Namespace Reference

Functions

static GrSurfaceProxyView create_falloff_texture (GrRecordingContext *rContext)
 
GrOp::Owner Make (GrRecordingContext *context, GrColor color, const SkMatrix &viewMatrix, const SkRRect &rrect, SkScalar blurWidth, SkScalar insetWidth)
 

Function Documentation

◆ create_falloff_texture()

static GrSurfaceProxyView skgpu::ganesh::ShadowRRectOp::create_falloff_texture ( GrRecordingContext rContext)
static

Definition at line 671 of file ShadowRRectOp.cpp.

671 {
674 skgpu::UniqueKey::Builder builder(&key, kDomain, 0, "Shadow Gaussian Falloff");
675 builder.finish();
676
677 auto threadSafeCache = rContext->priv().threadSafeCache();
678
679 GrSurfaceProxyView view = threadSafeCache->find(key);
680 if (view) {
682 return view;
683 }
684
685 static const int kWidth = 128;
686 static const size_t kRowBytes = kWidth * GrColorTypeBytesPerPixel(GrColorType::kAlpha_8);
688
690 bitmap.allocPixels(ii, kRowBytes);
691
692 unsigned char* values = (unsigned char*)bitmap.getPixels();
693 for (int i = 0; i < 128; ++i) {
695 values[i] = SkScalarRoundToInt((SkScalarExp(-4 * d * d) - 0.018f) * 255);
696 }
697 bitmap.setImmutable();
698
700 if (!view) {
701 return {};
702 }
703
704 view = threadSafeCache->add(key, view);
706 return view;
707}
static constexpr size_t GrColorTypeBytesPerPixel(GrColorType ct)
Definition: GrTypesPriv.h:896
@ kTopLeft_GrSurfaceOrigin
Definition: GrTypes.h:148
#define SkASSERT(cond)
Definition: SkAssert.h:116
std::tuple< GrSurfaceProxyView, GrColorType > GrMakeUncachedBitmapProxyView(GrRecordingContext *rContext, const SkBitmap &bitmap, skgpu::Mipmapped mipmapped, SkBackingFit fit, skgpu::Budgeted budgeted)
Definition: SkGr.cpp:253
#define SkScalarExp(x)
Definition: SkScalar.h:51
#define SK_Scalar1
Definition: SkScalar.h:18
#define SkScalarRoundToInt(x)
Definition: SkScalar.h:37
#define SkIntToScalar(x)
Definition: SkScalar.h:57
GrThreadSafeCache * threadSafeCache()
GrRecordingContextPriv priv()
GrSurfaceOrigin origin() const
static Domain GenerateDomain()
Definition: ResourceKey.cpp:27
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE auto & d
Definition: main.cc:19
float SkScalar
Definition: extension.cpp:12
Definition: bitmap.py:1
const myers::Point & get< 0 >(const myers::Segment &s)
Definition: Myers.h:80
static SkImageInfo MakeA8(int width, int height)
constexpr size_t kWidth

◆ Make()

GrOp::Owner skgpu::ganesh::ShadowRRectOp::Make ( GrRecordingContext context,
GrColor  color,
const SkMatrix viewMatrix,
const SkRRect rrect,
SkScalar  blurWidth,
SkScalar  insetWidth 
)

Definition at line 709 of file ShadowRRectOp.cpp.

714 {
715 // Shadow rrect ops only handle simple circular rrects.
717
718 GrSurfaceProxyView falloffView = create_falloff_texture(context);
719 if (!falloffView) {
720 return nullptr;
721 }
722
723 // Do any matrix crunching before we reset the draw state for device coords.
724 const SkRect& rrectBounds = rrect.getBounds();
726 viewMatrix.mapRect(&bounds, rrectBounds);
727
728 // Map radius and inset. As the matrix is a similarity matrix, this should be isotropic.
730 SkScalar matrixFactor = viewMatrix[SkMatrix::kMScaleX] + viewMatrix[SkMatrix::kMSkewX];
731 SkScalar scaledRadius = SkScalarAbs(radius*matrixFactor);
732 SkScalar scaledInsetWidth = SkScalarAbs(insetWidth*matrixFactor);
733
734 if (scaledInsetWidth <= 0) {
735 return nullptr;
736 }
737
738 return GrOp::Make<ShadowCircularRRectOp>(context,
739 color,
740 bounds,
741 scaledRadius,
742 rrect.isOval(),
743 blurWidth,
744 scaledInsetWidth,
745 std::move(falloffView));
746}
#define SkScalarAbs(x)
Definition: SkScalar.h:39
static constexpr int kMScaleX
horizontal scale factor
Definition: SkMatrix.h:353
bool isSimilarity(SkScalar tol=SK_ScalarNearlyZero) const
Definition: SkMatrix.cpp:180
static constexpr int kMSkewX
horizontal skew factor
Definition: SkMatrix.h:354
bool mapRect(SkRect *dst, const SkRect &src, SkApplyPerspectiveClip pc=SkApplyPerspectiveClip::kYes) const
Definition: SkMatrix.cpp:1141
static bool EqualRadii(const SkRRect &rr)
Definition: SkRRectPriv.h:35
static SkVector GetSimpleRadii(const SkRRect &rr)
Definition: SkRRectPriv.h:22
bool isOval() const
Definition: SkRRect.h:85
const SkRect & getBounds() const
Definition: SkRRect.h:279
DlColor color
Optional< SkRect > bounds
Definition: SkRecords.h:189
SkRRect rrect
Definition: SkRecords.h:232
static GrSurfaceProxyView create_falloff_texture(GrRecordingContext *rContext)
float fX
x-axis value
Definition: SkPoint_impl.h:164