Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 3d906e0b3831fde723f8c3efe42fa846d4f6da08
      
https://github.com/WebKit/WebKit/commit/3d906e0b3831fde723f8c3efe42fa846d4f6da08
  Author: Ahmad Saleem <[email protected]>
  Date:   2026-09-06 (Sun, 06 Sep 2026)

  Changed paths:
    M Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp
    M Source/WebCore/html/canvas/CanvasStyle.h

  Log Message:
  -----------
  [Canvas] Reduce redundant state() and refcount churn in 
CanvasRenderingContext2DBase
https://bugs.webkit.org/show_bug.cgi?id=323415
rdar://186646617

Reviewed by Chris Dumez.

Several hot canvas paths repeatedly re-resolved the current state or churned
refcounts to read values that don't change within the call. These are pure
cleanups with no behavior change:

- applyLineDash() re-fetched m_stateStack.last() via state() on every loop
  iteration (both the size() bound and each lineDash[i] access). Hoist it into
  a single local reference.

- setLineDash() called modifiableState() up to three times; hoist into one
  local reference.

- clearCanvas(), rectContainsCanvas(), calculateCompositingBufferRect() and
  compositeBuffer() built the canvas rect as
  protect(canvasBase())->width()/height(), constructing a temporary Ref (and
  its ref/deref) twice per line. Use the existing backingStoreBounds() helper
  instead. That helper is already used elsewhere in this file and reads
  canvasBase().size() directly, so this removes the redundant per-read Ref
  churn without introducing any new unprotected access; confirmed no new
  alpha.webkit.Uncounted/Unchecked* analyzer warnings on the changed lines.

- The CG fillText()/strokeText() path tested drawStyle.canvasGradient() ||
  drawStyle.canvasPattern(), each returning a RefPtr purely for a presence
  test -- two refcount round-trips per styled text draw. Add
  CanvasStyle::isGradientOrPattern(), which for the three-alternative variant
  is exactly "not a Color", so the check constructs no RefPtr at all.

* Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp:
(WebCore::CanvasRenderingContext2DBase::setLineDash):
(WebCore::CanvasRenderingContext2DBase::applyLineDash const):
(WebCore::CanvasRenderingContext2DBase::clearCanvas):
(WebCore::CanvasRenderingContext2DBase::rectContainsCanvas const):
(WebCore::CanvasRenderingContext2DBase::calculateCompositingBufferRect):
(WebCore::CanvasRenderingContext2DBase::compositeBuffer):
(WebCore::CanvasRenderingContext2DBase::drawTextUnchecked):
* Source/WebCore/html/canvas/CanvasStyle.h:
(WebCore::CanvasStyle::isGradientOrPattern const):

Canonical link: https://commits.webkit.org/320594@main



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications

Reply via email to