RESOLVED FIXED179595
Clean up gradient code in preparation for conic gradients
https://bugs.webkit.org/show_bug.cgi?id=179595
Summary Clean up gradient code in preparation for conic gradients
Sam Weinig
Reported 2017-11-12 09:26:49 PST
Clean up gradient code in preparation for conic gradients
Attachments
Patch (55.90 KB, patch)
2017-11-12 09:44 PST, Sam Weinig
no flags
Patch (55.88 KB, patch)
2017-11-12 10:13 PST, Sam Weinig
no flags
Patch (55.88 KB, patch)
2017-11-12 11:41 PST, Sam Weinig
no flags
Patch (56.09 KB, patch)
2017-11-19 13:54 PST, Sam Weinig
no flags
Patch (56.09 KB, patch)
2017-11-19 14:03 PST, Sam Weinig
no flags
Sam Weinig
Comment 1 2017-11-12 09:44:50 PST
Sam Weinig
Comment 2 2017-11-12 10:13:22 PST
Sam Weinig
Comment 3 2017-11-12 11:41:35 PST
Darin Adler
Comment 4 2017-11-12 15:59:41 PST
Comment on attachment 326723 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=326723&action=review > Source/WebCore/css/CSSGradientValue.cpp:138 > +struct LinearGradientAdaptor { Unclear to me why this is a struct rather than a class. > Source/WebCore/css/CSSGradientValue.cpp:139 > + LinearGradientAdaptor(Gradient::LinearData& data) Should mark this explicit since it’s not for type conversion. > Source/WebCore/css/CSSGradientValue.cpp:161 > + data.point0 = FloatPoint(p0.x() + firstOffset * (p1.x() - p0.x()), p0.y() + firstOffset * (p1.y() - p0.y())); > + data.point1 = FloatPoint(p1.x() + (lastOffset - 1) * (p1.x() - p0.x()), p1.y() + (lastOffset - 1) * (p1.y() - p0.y())); Can we use { } instead of FloatPoint( ) here? > Source/WebCore/css/CSSGradientValue.cpp:172 > +struct RadialGradientAdaptor { Unclear to me why this is a struct rather than a class. > Source/WebCore/css/CSSGradientValue.cpp:173 > + RadialGradientAdaptor(Gradient::RadialData& data) Should mark this explicit since it’s not for type conversion. > Source/WebCore/css/CSSGradientValue.cpp:179 > + FloatPoint startPoint() { return data.point0; } > + FloatPoint endPoint() { return data.point0 + FloatSize(data.endRadius, 0); } Should be const. Might use FloatSize { } instead of FloatSize( ). > Source/WebCore/css/CSSGradientValue.cpp:230 > + for (auto& stop : stops) > + stop.offset /= scale; Is it more efficient to invert scale and use *= inside the loop? > Source/WebCore/css/CSSGradientValue.cpp:239 > +template<class GradientAdaptor> I normally use typename rather than class. Also, I often put these on the same line, but in this case that would be a long one so maybe not. > Source/WebCore/css/CSSGradientValue.cpp:267 > + FloatSize gradientSize(gradientStart - gradientEnd); Consider this: auto gradientSize = gradientStart - gradientEnd; > Source/WebCore/css/CSSGradientValue.cpp:827 > + LinearGradientAdaptor adaptor { data }; What's the argument for adaptor vs. adapter in these names? I would be tempted to just always use the more common spelling "adapter". > Source/WebCore/css/CSSGradientValue.h:112 > + template<class GradientAdaptor> typename > Source/WebCore/platform/graphics/Gradient.h:92 > + enum class Type { > + Linear, > + Radial > + }; I like these kinds of things as one-liners. > Source/WebCore/platform/graphics/Gradient.h:97 > + static Ref<Gradient> create(LinearData&& data) > + { > + return adoptRef(*new Gradient(WTFMove(data))); > + } I’ve been learning towards putting these create function bodies in cpp files and inlining the constructors instead of inlining the create functions. Smaller at each call site, roughly the same number of function calls. > Source/WebCore/platform/graphics/Gradient.h:111 > + const Variant<LinearData, RadialData>& data() const { return m_data; } Could consider: using Data = Variant<LinearData, RadialData>; Then we would have members Data ("type member"), data (function member), and m_data (data member). I did something similar in my recent work in another class. > Source/WebCore/platform/graphics/Gradient.h:124 > + AffineTransform gradientSpaceTransform() { return m_gradientSpaceTransformation; } Make this const? Return a const& since AffineTransform is really big?
Sam Weinig
Comment 5 2017-11-19 13:54:15 PST
Sam Weinig
Comment 6 2017-11-19 14:03:43 PST
WebKit Commit Bot
Comment 7 2017-11-19 15:06:07 PST
Comment on attachment 327350 [details] Patch Clearing flags on attachment: 327350 Committed r225036: <https://trac.webkit.org/changeset/225036>
WebKit Commit Bot
Comment 8 2017-11-19 15:06:08 PST
All reviewed patches have been landed. Closing bug.
Radar WebKit Bug Importer
Comment 9 2017-11-19 15:07:40 PST
Note You need to log in before you can comment on or make changes to this bug.