Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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) {
694 SkScalar d = SK_Scalar1 - i / SkIntToScalar(127);
695 values[i] = SkScalarRoundToInt((SkScalarExp(-4 * d * d) - 0.018f) * 255);
696 }
697 bitmap.setImmutable();
698
699 view = std::get<0>(GrMakeUncachedBitmapProxyView(rContext, bitmap));
700 if (!view) {
701 return {};
702 }
703
704 view = threadSafeCache->add(key, view);
706 return view;
707}
static constexpr size_t GrColorTypeBytesPerPixel(GrColorType ct)
@ 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()
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE auto & d
Definition main.cc:19
float SkScalar
Definition extension.cpp:12
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.
716 SkASSERT(viewMatrix.isSimilarity() && SkRRectPriv::EqualRadii(rrect));
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();
725 SkRect bounds;
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}
SkColor4f color
#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
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
static GrSurfaceProxyView create_falloff_texture(GrRecordingContext *rContext)
float fX
x-axis value