MCPcopy Create free account
hub / github.com/Snapchat/Valdi / updateShader

Method updateShader

snap_drawing/src/snap_drawing/cpp/Drawing/RadialGradient.cpp:40–80  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

38}
39
40void RadialGradient::updateShader(const Rect& bounds) {
41 if (isEmpty()) {
42 _shader = nullptr;
43 } else {
44 auto width = bounds.width();
45 auto height = bounds.height();
46 auto radius = std::min(width / 2, height / 2);
47
48 const auto* colorsData = reinterpret_cast<const SkColor*>(_colors.data());
49
50 SkMatrix localMatrix;
51 if (width != height) {
52 localMatrix.postScale(width / height, 1);
53 }
54 localMatrix.postTranslate(bounds.x() + (width / 2), bounds.y() + (height / 2));
55
56 sk_sp<SkShader> shader;
57 if (_colors.size() == _locations.size()) {
58 // User provided color distribution
59
60 _shader = SkGradientShader::MakeRadial(Point::make(0, 0).getSkValue(),
61 radius,
62 colorsData,
63 _locations.data(),
64 static_cast<int>(_colors.size()),
65 SkTileMode::kClamp,
66 0,
67 &localMatrix);
68 } else {
69 // Distribute colors evenly
70 _shader = SkGradientShader::MakeRadial(Point::make(0, 0).getSkValue(),
71 radius,
72 colorsData,
73 nullptr,
74 static_cast<int>(_colors.size()),
75 SkTileMode::kClamp,
76 0,
77 &localMatrix);
78 }
79 }
80}
81
82void RadialGradient::applyToPaint(Paint& paint) const {
83 paint.getSkValue().setShader(_shader);

Callers

nothing calls this directly

Calls 10

isEmptyFunction · 0.85
minFunction · 0.85
postScaleMethod · 0.80
xMethod · 0.80
yMethod · 0.80
getSkValueMethod · 0.80
widthMethod · 0.45
heightMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected