RESOLVED FIXED 51312
Make ContextShadow code cross-platform
https://bugs.webkit.org/show_bug.cgi?id=51312
Summary Make ContextShadow code cross-platform
Simon Fraser (smfr)
Reported 2010-12-19 16:04:29 PST
It would be nice if ContextShadow::drawRectShadow() were cross-platform. ImageBuffer could be used here, but we'd need direct pixel access to avoid having to copy to do blurring (see bug 51297). Also somewhat related, bug 51309 talks about sharing blurring code between ContextShadow and FEGaussianBlur.
Attachments
Patch (35.16 KB, patch)
2011-01-16 14:14 PST, Dirk Schulze
no flags
Patch (37.60 KB, patch)
2011-01-30 15:55 PST, Simon Fraser (smfr)
no flags
Patch (38.27 KB, patch)
2011-01-30 16:37 PST, Simon Fraser (smfr)
sam: review+
Dirk Schulze
Comment 1 2010-12-19 22:59:53 PST
Hm, Qt and Cairo already use ContextShadow, why would CG and Skia need ContextShadow? Both have an own implementation? Is the quality not good enough?
Ariya Hidayat
Comment 2 2010-12-20 08:09:22 PST
Qt does not use ContextShadow::drawRectShadow(), though.
Simon Fraser (smfr)
Comment 3 2010-12-20 08:49:32 PST
I want to use ContextShadow for CG, because CG's shadows are slow, and have an incorrect radius.
Hajime Morrita
Comment 4 2010-12-21 18:55:06 PST
Just for curiosity, will this fix Bug 51386 ?
Ariya Hidayat
Comment 5 2010-12-22 18:41:31 PST
> Just for curiosity, will this fix Bug 51386 ? Likely not.
Dirk Schulze
Comment 6 2011-01-05 00:27:58 PST
(In reply to comment #0) > It would be nice if ContextShadow::drawRectShadow() were cross-platform. ImageBuffer could be used here, but we'd need direct pixel access to avoid having to copy to do blurring (see bug 51297). > > Also somewhat related, bug 51309 talks about sharing blurring code between ContextShadow and FEGaussianBlur. At least for drawRectShadow() I don't believe that direct pixel access makes a big difference. I bet (you may have checked for your self), that the general case will be 100x100 pixel for the temporary ImageBuffer for blurring operations. The copy operations carry no weight for such a small image. I don't want to prevent you to add direct pixel access, but the first implementation doesn't need to have it.
Simon Fraser (smfr)
Comment 7 2011-01-05 08:34:49 PST
(In reply to comment #6) > (In reply to comment #0) > > It would be nice if ContextShadow::drawRectShadow() were cross-platform. ImageBuffer could be used here, but we'd need direct pixel access to avoid having to copy to do blurring (see bug 51297). > > > > Also somewhat related, bug 51309 talks about sharing blurring code between ContextShadow and FEGaussianBlur. > > At least for drawRectShadow() I don't believe that direct pixel access makes a big difference. I bet (you may have checked for your self), that the general case will be 100x100 pixel for the temporary ImageBuffer for blurring operations. The copy operations carry no weight for such a small image. I don't want to prevent you to add direct pixel access, but the first implementation doesn't need to have it. I agree that in my measurements the blur cost was much higher than the copy.
Dirk Schulze
Comment 8 2011-01-16 14:14:13 PST
Dirk Schulze
Comment 9 2011-01-17 00:52:15 PST
(In reply to comment #8) > Created an attachment (id=79112) [details] > Patch The patch just adds ContextShadow to all build systems (including Mac). Added support for horizontal and vertical blurring with different blur radii as well.
Nikolas Zimmermann
Comment 10 2011-01-17 08:09:00 PST
Comment on attachment 79112 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=79112&action=review I'm tempted to r+ this, though the public variables in ContextShadow lead to a r-. Who allowed this to be landed? :-) > Source/WebCore/platform/graphics/ContextShadow.h:82 > + ContextShadowType m_type; > > Color m_color; > - int m_blurDistance; > + IntSize m_blurDistance; > FloatSize m_offset; public variables? This needs to be hidden....
Dirk Schulze
Comment 11 2011-01-17 09:58:07 PST
(In reply to comment #10) > (From update of attachment 79112 [details]) > View in context: https://bugs.webkit.org/attachment.cgi?id=79112&action=review > > I'm tempted to r+ this, though the public variables in ContextShadow lead to a r-. Who allowed this to be landed? :-) > > > Source/WebCore/platform/graphics/ContextShadow.h:82 > > + ContextShadowType m_type; > > > > Color m_color; > > - int m_blurDistance; > > + IntSize m_blurDistance; > > FloatSize m_offset; > > public variables? > This needs to be hidden.... I thought the same :-) But Simon already opened another bug for cleaning up ContextShadow. It was not my intention to clean up ContextShadow in the first place.
Ariya Hidayat
Comment 12 2011-01-17 10:17:35 PST
> I'm tempted to r+ this, though the public variables in ContextShadow lead to a r-. Who allowed this to be landed? :-) > > > Source/WebCore/platform/graphics/ContextShadow.h:82 > > + ContextShadowType m_type; > > > > Color m_color; > > - int m_blurDistance; > > + IntSize m_blurDistance; > > FloatSize m_offset; > > public variables? > This needs to be hidden.... Because it was a private, lightweight helper struct for Qt port only. Then it got adopted by everyone.
Simon Fraser (smfr)
Comment 13 2011-01-17 10:20:34 PST
Yeah, I think ContextShadow should be properly class-ified, and maybe given a better name.
WebKit Review Bot
Comment 14 2011-01-17 17:39:11 PST
Simon Fraser (smfr)
Comment 15 2011-01-30 10:43:12 PST
I'm going to make a new class that platforms can migrate to over time.
Simon Fraser (smfr)
Comment 16 2011-01-30 15:55:04 PST
Sam Weinig
Comment 17 2011-01-30 16:12:04 PST
Comment on attachment 80605 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=80605&action=review > Source/WebCore/platform/graphics/ShadowBlur.cpp:47 > +static inline int roundUpToMultipleOf32(int d) > +{ > + return (1 + (d >> 5)) << 5; > +} Maybe this should go in MathExtras.h > Source/WebCore/platform/graphics/ShadowBlur.cpp:77 > + const double scratchBufferPurgeInterval = 2; This should probably be a static const. > Source/WebCore/platform/graphics/ShadowBlur.cpp:112 > + // See comments in http://webkit.org/b/40793, it seems sensible > + // to follow Skia's limit of 128 pixels of blur radius I think putting the reason would be more helpful than putting the link. > Source/WebCore/platform/graphics/ShadowBlur.cpp:127 > + } else { > + m_type = SolidShadow; > + } The braces are not needed in this clause. > Source/WebCore/platform/graphics/ShadowBlur.cpp:132 > +static const int BlurSumShift = 15; > +static const float GaussianKernelFactor = 3 / 4.f * sqrtf(2 * piFloat); We don't traditionally capitalize constant names. I am also not sure if calling sqrtf() for a static const will work in all environments. > Source/WebCore/platform/graphics/ShadowBlur.cpp:148 > + int d; d is really not the most descriptive name. How about diameter (if that is what it is)? > Source/WebCore/platform/graphics/ShadowBlur.cpp:158 > + int dmax = d >> 1; > + int dmin = dmax - 1 + (d & 1); > + if (dmin < 0) > + dmin = 0; > + Again, not great names. > Source/WebCore/platform/graphics/ShadowBlur.cpp:166 > + unsigned char* pixels = imageData; > + int stride = (!k) ? 4 : rowStride; > + int delta = (!k) ? rowStride : 4; > + int jfinal = (!k) ? size.height() : size.width(); > + int dim = (!k) ? size.width() : size.height(); The parens around !k are not necessary. jfinal should probably be jFinal. > Source/WebCore/platform/graphics/ShadowBlur.cpp:298 > + const int frameSize = inflation * 2; > + m_sourceRect = IntRect(0, 0, shadowedRect.width() + frameSize, shadowedRect.height() + frameSize); > + m_layerOrigin = FloatPoint(layerFloatRect.x(), layerFloatRect.y()); > + m_layerSize = layerFloatRect.size(); > + > + const FloatPoint m_unclippedLayerOrigin = FloatPoint(unclippedLayerRect.x(), unclippedLayerRect.y()); > + const FloatSize clippedOut = m_unclippedLayerOrigin - m_layerOrigin; > + > + // Set the origin as the top left corner of the scratch image, or, in case there's a clipped > + // out region, set the origin accordingly to the full bounding rect's top-left corner. > + const float translationX = -shadowedRect.x() + inflation - fabsf(clippedOut.width()); > + const float translationY = -shadowedRect.y() + inflation - fabsf(clippedOut.height()); > + m_layerContextTranslation = FloatSize(translationX, translationY); I don't know if the use of const here is adding anything.
Simon Fraser (smfr)
Comment 18 2011-01-30 16:37:00 PST
Simon Fraser (smfr)
Comment 19 2011-01-30 16:45:08 PST
Note You need to log in before you can comment on or make changes to this bug.