Skip to content

Commit

Permalink
Remove GraphicsContext::getShadow and ::setShadow
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=259233
rdar://112296081

Reviewed by Simon Fraser.

Replace uses of GraphicsContext::getShadow() with ::getDropShadow() and
::setShadow() with ::setDropShadow(). This is in preparation for merging
m_dropShadow in GraphicsContextState with m_style.

Refactoring - no functional changes.

Combined changes:
* Source/WebCore/Modules/system-preview/ARKitBadgeSystemImage.mm:
(WebCore::ARKitBadgeSystemImage::draw const):
* Source/WebCore/display/css/DisplayBoxDecorationPainter.cpp:
(WebCore::Display::BoxDecorationPainter::paintBoxShadow const):
* Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp:
(WebCore::CanvasRenderingContext2DBase::clearRect):
(WebCore::CanvasRenderingContext2DBase::applyShadow):
(WebCore::CanvasRenderingContext2DBase::drawTextUnchecked):
* Source/WebCore/page/DebugPageOverlays.cpp:
(WebCore::InteractionRegionOverlay::drawSettings):
* Source/WebCore/platform/graphics/GraphicsContext.cpp:
(WebCore::GraphicsContext::getShadow const): Deleted.
* Source/WebCore/platform/graphics/GraphicsContext.h:
(WebCore::GraphicsContext::setShadow): Deleted.
* Source/WebCore/platform/graphics/coretext/FontCascadeCoreText.cpp:
(WebCore::FontCascade::drawGlyphs):
* Source/WebCore/rendering/BackgroundPainter.cpp:
(WebCore::applyBoxShadowForBackground):
(WebCore::BackgroundPainter::paintBoxShadow):
* Source/WebCore/rendering/EllipsisBoxPainter.cpp:
(WebCore::EllipsisBoxPainter::paint):
* Source/WebCore/rendering/RenderThemeIOS.mm:
(WebCore::RenderThemeIOS::paintTextFieldInnerShadow):
(WebCore::RenderThemeIOS::paintCheckboxRadioInnerShadow):
* Source/WebCore/rendering/TextDecorationPainter.cpp:
(WebCore::TextDecorationPainter::paintBackgroundDecorations):
* Source/WebCore/rendering/TextPainter.cpp:
* Source/WebKit/WebProcess/WebPage/FindController.cpp:
(WebKit::FindController::drawRect):
* Source/WebKit/WebProcess/WebPage/WebFoundTextRangeController.cpp:
(WebKit::WebFoundTextRangeController::drawRect):

Canonical link: https://commits.webkit.org/266116@main
  • Loading branch information
tuankiet65 committed Jul 17, 2023
1 parent 886fe1f commit bde6731
Show file tree
Hide file tree
Showing 14 changed files with 28 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@
// Use the GraphicsContext function, because it calculates the blur radius in context space,
// rather than screen space.
constexpr auto shadowColor = Color::black.colorWithAlphaByte(26);
graphicsContext.setShadow(FloatSize { }, 16, shadowColor);
graphicsContext.setDropShadow({ { }, 16, shadowColor, ShadowRadiusMode::Default });

// The circle must have an alpha channel value of 1 for the shadow color to appear.
CGFloat circleColorComponents[4] = { 0, 0, 0, 1 };
Expand Down
4 changes: 2 additions & 2 deletions Source/WebCore/display/css/DisplayBoxDecorationPainter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1301,7 +1301,7 @@ void BoxDecorationPainter::paintBoxShadow(PaintingContext& paintingContext, Shad
auto shadowRectOrigin = fillRect.rect().location() + shadowOffset;
auto adjustedShadowOffset = shadowRectOrigin - adjustedFillRect.rect().location();

paintingContext.context.setShadow(adjustedShadowOffset, shadowRadius.value(), resolveColor(shadow.color()), shadow.isWebkitBoxShadow() ? ShadowRadiusMode::Legacy : ShadowRadiusMode::Default);
paintingContext.context.setDropShadow({ adjustedShadowOffset, shadowRadius.value(), resolveColor(shadow.color()), shadow.isWebkitBoxShadow() ? ShadowRadiusMode::Legacy : ShadowRadiusMode::Default });

if (hasBorderRadius) {
// If the box is opaque, it is unnecessary to clip it out. However, doing so saves time
Expand Down Expand Up @@ -1412,7 +1412,7 @@ void BoxDecorationPainter::paintBoxShadow(PaintingContext& paintingContext, Shad
paintingContext.context.translate(extraOffset);
shadowOffset -= extraOffset;

paintingContext.context.setShadow(shadowOffset, shadowRadius.value(), resolveColor(shadow.color()), shadow.isWebkitBoxShadow() ? ShadowRadiusMode::Legacy : ShadowRadiusMode::Default);
paintingContext.context.setDropShadow({ shadowOffset, shadowRadius.value(), resolveColor(shadow.color()), shadow.isWebkitBoxShadow() ? ShadowRadiusMode::Legacy : ShadowRadiusMode::Default });
paintingContext.context.fillRectWithRoundedHole(shadowCastingRect, roundedHoleRect, fillColor);
};

Expand Down
19 changes: 7 additions & 12 deletions Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1234,7 +1234,7 @@ void CanvasRenderingContext2DBase::clearRect(double x, double y, double width, d
if (shouldDrawShadows()) {
context->save();
saved = true;
context->setShadow(FloatSize(), 0, Color::transparentBlack, ShadowRadiusMode::Legacy);
context->setDropShadow({ FloatSize(), 0, Color::transparentBlack, ShadowRadiusMode::Legacy });
}
if (state().globalAlpha != 1) {
if (!saved) {
Expand Down Expand Up @@ -1392,9 +1392,9 @@ void CanvasRenderingContext2DBase::applyShadow()
if (shouldDrawShadows()) {
float width = state().shadowOffset.width();
float height = state().shadowOffset.height();
c->setShadow(FloatSize(width, -height), state().shadowBlur, state().shadowColor, ShadowRadiusMode::Legacy);
c->setDropShadow({ FloatSize(width, -height), state().shadowBlur, state().shadowColor, ShadowRadiusMode::Legacy });
} else
c->setShadow(FloatSize(), 0, Color::transparentBlack, ShadowRadiusMode::Legacy);
c->setDropShadow({ FloatSize(), 0, Color::transparentBlack, ShadowRadiusMode::Legacy });
}

bool CanvasRenderingContext2DBase::shouldDrawShadows() const
Expand Down Expand Up @@ -2583,19 +2583,14 @@ void CanvasRenderingContext2DBase::drawTextUnchecked(const TextRun& textRun, dou

FloatSize offset(0, 2 * maskRect.height());

FloatSize shadowOffset;
float shadowRadius;
Color shadowColor;
c->getShadow(shadowOffset, shadowRadius, shadowColor);
auto shadow = c->dropShadow();

FloatRect shadowRect(maskRect);
shadowRect.inflate(shadowRadius * 1.4);
shadowRect.move(shadowOffset * -1);
shadowRect.inflate(shadow.blurRadius * 1.4);
shadowRect.move(shadow.offset * -1);
c->clip(shadowRect);

shadowOffset += offset;

c->setShadow(shadowOffset, shadowRadius, shadowColor, ShadowRadiusMode::Legacy);
c->setDropShadow({ shadow.offset + offset, shadow.blurRadius, shadow.color, ShadowRadiusMode::Legacy });

if (fill)
c->setFillColor(Color::black);
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/page/DebugPageOverlays.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ void InteractionRegionOverlay::drawSettings(GraphicsContext& context)

{
GraphicsContextStateSaver stateSaver(context);
context.setShadow({ }, 5, Color(Color::black).colorWithAlpha(0.5));
context.setDropShadow({ { }, 5, Color(Color::black).colorWithAlpha(0.5), ShadowRadiusMode::Default });
context.fillRoundedRect(FloatRoundedRect { rect, FloatRoundedRect::Radii { 6 } }, Color(Color::white).colorWithAlpha(0.85));
}

Expand Down
9 changes: 0 additions & 9 deletions Source/WebCore/platform/graphics/GraphicsContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,6 @@ void GraphicsContext::drawRaisedEllipse(const FloatRect& rect, const Color& elli
restore();
}

bool GraphicsContext::getShadow(FloatSize& offset, float& blur, Color& color) const
{
offset = dropShadow().offset;
blur = dropShadow().blurRadius;
color = dropShadow().color;

return hasShadow();
}

void GraphicsContext::beginTransparencyLayer(float)
{
++m_transparencyLayerCount;
Expand Down
4 changes: 0 additions & 4 deletions Source/WebCore/platform/graphics/GraphicsContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,6 @@ class GraphicsContext {
void setDropShadow(const DropShadow& dropShadow) { m_state.setDropShadow(dropShadow); didUpdateState(m_state); }
void clearShadow() { setDropShadow({ }); }

// FIXME: Use dropShadow() and setDropShadow() instead of calling these functions.
WEBCORE_EXPORT bool getShadow(FloatSize&, float&, Color&) const;
void setShadow(const FloatSize& offset, float blurRadius, const Color& color, ShadowRadiusMode shadowRadiusMode = ShadowRadiusMode::Default) { setDropShadow({ offset, blurRadius, color, shadowRadiusMode }); }

bool hasVisibleShadow() const { return dropShadow().isVisible(); }
bool hasBlurredShadow() const { return dropShadow().isBlurred(); }
bool hasShadow() const { return dropShadow().hasOutsets(); }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,10 +348,7 @@ void FontCascade::drawGlyphs(GraphicsContext& context, const Font& font, const G
setCGFontRenderingMode(context);
CGContextSetFontSize(cgContext, platformData.size());

FloatSize shadowOffset;
float shadowBlur;
Color shadowColor;
context.getShadow(shadowOffset, shadowBlur, shadowColor);
auto shadow = context.dropShadow();

AffineTransform contextCTM = context.getCTM();
float syntheticBoldOffset = font.syntheticBoldOffset();
Expand All @@ -364,16 +361,16 @@ void FontCascade::drawGlyphs(GraphicsContext& context, const Font& font, const G
}
};

bool hasSimpleShadow = context.textDrawingMode() == TextDrawingMode::Fill && shadowColor.isValid() && !shadowBlur && !platformData.isColorBitmapFont() && (!context.shadowsIgnoreTransforms() || contextCTM.isIdentityOrTranslationOrFlipped()) && !context.isInTransparencyLayer();
bool hasSimpleShadow = context.textDrawingMode() == TextDrawingMode::Fill && shadow.color.isValid() && !shadow.blurRadius && !platformData.isColorBitmapFont() && (!context.shadowsIgnoreTransforms() || contextCTM.isIdentityOrTranslationOrFlipped()) && !context.isInTransparencyLayer();
if (hasSimpleShadow) {
// Paint simple shadows ourselves instead of relying on CG shadows, to avoid losing subpixel antialiasing.
context.clearShadow();
Color fillColor = context.fillColor();
Color shadowFillColor = shadowColor.colorWithAlphaMultipliedBy(fillColor.alphaAsFloat());
Color shadowFillColor = shadow.color.colorWithAlphaMultipliedBy(fillColor.alphaAsFloat());
context.setFillColor(shadowFillColor);
float shadowTextX = point.x() + shadowOffset.width();
float shadowTextX = point.x() + shadow.offset.width();
// If shadows are ignoring transforms, then we haven't applied the Y coordinate flip yet, so down is negative.
float shadowTextY = point.y() + shadowOffset.height() * (context.shadowsIgnoreTransforms() ? -1 : 1);
float shadowTextY = point.y() + shadow.offset.height() * (context.shadowsIgnoreTransforms() ? -1 : 1);
showGlyphsWithAdvances(FloatPoint(shadowTextX, shadowTextY), font, cgContext, glyphs, advances, numGlyphs, textMatrix);
if (syntheticBoldOffset)
showGlyphsWithAdvances(FloatPoint(shadowTextX + syntheticBoldOffset, shadowTextY), font, cgContext, glyphs, advances, numGlyphs, textMatrix);
Expand All @@ -386,7 +383,7 @@ void FontCascade::drawGlyphs(GraphicsContext& context, const Font& font, const G
showGlyphsWithAdvances(FloatPoint(point.x() + syntheticBoldOffset, point.y()), font, cgContext, glyphs, advances, numGlyphs, textMatrix);

if (hasSimpleShadow)
context.setShadow(shadowOffset, shadowBlur, shadowColor);
context.setDropShadow(shadow);

#if !PLATFORM(IOS_FAMILY)
if (shouldSmoothFonts != originalShouldUseFontSmoothing)
Expand Down
6 changes: 3 additions & 3 deletions Source/WebCore/rendering/BackgroundPainter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ static void applyBoxShadowForBackground(GraphicsContext& context, const RenderSt
boxShadow = boxShadow->next();

FloatSize shadowOffset(boxShadow->x().value(), boxShadow->y().value());
context.setShadow(shadowOffset, boxShadow->radius().value(), style.colorWithColorFilter(boxShadow->color()), boxShadow->isWebkitBoxShadow() ? ShadowRadiusMode::Legacy : ShadowRadiusMode::Default);
context.setDropShadow({ shadowOffset, boxShadow->radius().value(), style.colorWithColorFilter(boxShadow->color()), boxShadow->isWebkitBoxShadow() ? ShadowRadiusMode::Legacy : ShadowRadiusMode::Default });
}

void BackgroundPainter::paintFillLayer(const Color& color, const FillLayer& bgLayer, const LayoutRect& rect,
Expand Down Expand Up @@ -850,7 +850,7 @@ void BackgroundPainter::paintBoxShadow(const LayoutRect& paintRect, const Render
FloatPoint snappedShadowOrigin = FloatPoint(roundToDevicePixel(shadowRectOrigin.x(), deviceScaleFactor), roundToDevicePixel(shadowRectOrigin.y(), deviceScaleFactor));
FloatSize snappedShadowOffset = snappedShadowOrigin - pixelSnappedFillRect.rect().location();

context.setShadow(snappedShadowOffset, shadowRadius, shadowColor, shadow->isWebkitBoxShadow() ? ShadowRadiusMode::Legacy : ShadowRadiusMode::Default);
context.setDropShadow({ snappedShadowOffset, shadowRadius, shadowColor, shadow->isWebkitBoxShadow() ? ShadowRadiusMode::Legacy : ShadowRadiusMode::Default });

if (hasBorderRadius) {
// If the box is opaque, it is unnecessary to clip it out. However, doing so saves time
Expand Down Expand Up @@ -952,7 +952,7 @@ void BackgroundPainter::paintBoxShadow(const LayoutRect& paintRect, const Render
shadowOffset -= extraOffset;

auto snappedShadowOffset = roundSizeToDevicePixels(shadowOffset, deviceScaleFactor);
context.setShadow(snappedShadowOffset, shadowRadius, shadowColor, shadow->isWebkitBoxShadow() ? ShadowRadiusMode::Legacy : ShadowRadiusMode::Default);
context.setDropShadow({ snappedShadowOffset, shadowRadius, shadowColor, shadow->isWebkitBoxShadow() ? ShadowRadiusMode::Legacy : ShadowRadiusMode::Default });
context.fillRectWithRoundedHole(pixelSnappedOuterRect, pixelSnappedHoleRect, fillColor);
}
}
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/rendering/EllipsisBoxPainter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void EllipsisBoxPainter::paint()
auto setShadow = false;
if (style.textShadow()) {
auto shadowColor = style.colorWithColorFilter(style.textShadow()->color());
context.setShadow(LayoutSize(style.textShadow()->x().value(), style.textShadow()->y().value()), style.textShadow()->radius().value(), shadowColor);
context.setDropShadow({ LayoutSize(style.textShadow()->x().value(), style.textShadow()->y().value()), style.textShadow()->radius().value(), shadowColor, ShadowRadiusMode::Default });
setShadow = true;
}

Expand Down
6 changes: 3 additions & 3 deletions Source/WebCore/rendering/RenderThemeIOS.mm
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ static void drawJoinedLines(CGContextRef context, const Vector<CGPoint>& points,
const FloatSize innerShadowOffset { 0, 5 };
constexpr auto innerShadowBlur = 10.0f;
auto innerShadowColor = DisplayP3<float> { 0, 0, 0, 0.04f };
context.setShadow(innerShadowOffset, innerShadowBlur, innerShadowColor);
context.setDropShadow({ innerShadowOffset, innerShadowBlur, innerShadowColor, ShadowRadiusMode::Default });
context.setFillColor(Color::black);

Path innerShadowPath;
Expand Down Expand Up @@ -1852,7 +1852,7 @@ static void paintAttachmentBorder(GraphicsContext& context, Path& borderPath)

bool isEmpty = !states.containsAny({ ControlStates::States::Checked, ControlStates::States::Indeterminate });
auto firstShadowColor = DisplayP3<float> { 0, 0, 0, isEmpty ? 0.05f : 0.1f };
context.setShadow(innerShadowOffset, innerShadowBlur, firstShadowColor);
context.setDropShadow({ innerShadowOffset, innerShadowBlur, firstShadowColor, ShadowRadiusMode::Default });
context.setFillColor(Color::black);

Path innerShadowPath;
Expand All @@ -1869,7 +1869,7 @@ static void paintAttachmentBorder(GraphicsContext& context, Path& borderPath)
context.fillPath(innerShadowPath);

constexpr auto secondShadowColor = DisplayP3<float> { 1, 1, 1, 0.5f };
context.setShadow(FloatSize { 0, 0 }, 1, secondShadowColor);
context.setDropShadow({ FloatSize { 0, 0 }, 1, secondShadowColor, ShadowRadiusMode::Default });

context.fillPath(innerShadowPath);
}
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/rendering/TextDecorationPainter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ void TextDecorationPainter::paintBackgroundDecorations(const RenderStyle& style,

auto shadowX = m_isHorizontal ? shadow->x().value() : shadow->y().value();
auto shadowY = m_isHorizontal ? shadow->y().value() : -shadow->x().value();
m_context.setShadow(FloatSize { shadowX, shadowY - extraOffset }, shadow->radius().value(), shadowColor);
m_context.setDropShadow({ FloatSize { shadowX, shadowY - extraOffset }, shadow->radius().value(), shadowColor, ShadowRadiusMode::Default });
shadow = shadow->next();
};
applyShadowIfNeeded();
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/rendering/TextPainter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ ShadowApplier::ShadowApplier(const RenderStyle& style, GraphicsContext& context,
}

if (!m_avoidDrawingShadow)
context.setShadow(shadowOffset, shadowRadius.value(), shadowColor);
context.setDropShadow({ shadowOffset, shadowRadius.value(), shadowColor, ShadowRadiusMode::Default });
}

inline bool ShadowApplier::isLastShadowIteration()
Expand Down
2 changes: 1 addition & 1 deletion Source/WebKit/WebProcess/WebPage/FindController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ void FindController::drawRect(PageOverlay&, GraphicsContext& graphicsContext, co

// Draw white frames around the holes.
// We double the thickness because half of the stroke will be erased when we clear the holes.
graphicsContext.setShadow(FloatSize(shadowOffsetX, shadowOffsetY), shadowBlurRadius, shadowColor);
graphicsContext.setDropShadow({ FloatSize(shadowOffsetX, shadowOffsetY), shadowBlurRadius, shadowColor, ShadowRadiusMode::Default });
graphicsContext.setStrokeColor(Color::white);
graphicsContext.setStrokeThickness(borderWidth * 2);
for (auto& path : whiteFramePaths)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ void WebFoundTextRangeController::drawRect(WebCore::PageOverlay&, WebCore::Graph

WebCore::GraphicsContextStateSaver stateSaver(graphicsContext);

graphicsContext.setShadow(WebCore::FloatSize(shadowOffsetX, shadowOffsetY), shadowBlurRadius, shadowColor);
graphicsContext.setDropShadow({ WebCore::FloatSize(shadowOffsetX, shadowOffsetY), shadowBlurRadius, shadowColor, ShadowRadiusMode::Default });
graphicsContext.setStrokeColor(foundColor);
graphicsContext.setStrokeThickness(indicatorBorderWidth * 2);
for (auto& path : foundFramePaths)
Expand Down

0 comments on commit bde6731

Please sign in to comment.