[webkit-changes] [WebKit/WebKit] 44522d: Refactor Canvas Post-Processing logic in CanvasBase

Matthew Finkel noreply at github.com
Thu May 4 13:53:50 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 44522d1c3a43d38639df8760d6be6ad964470f46
      https://github.com/WebKit/WebKit/commit/44522d1c3a43d38639df8760d6be6ad964470f46
  Author: Matthew Finkel <sysrqb at apple.com>
  Date:   2023-05-04 (Thu, 04 May 2023)

  Changed paths:
    M Source/WebCore/html/CanvasBase.cpp
    M Source/WebCore/html/CanvasBase.h
    M Source/WebCore/html/CustomPaintCanvas.h
    M Source/WebCore/html/HTMLCanvasElement.cpp
    M Source/WebCore/html/HTMLCanvasElement.h
    M Source/WebCore/html/OffscreenCanvas.cpp
    M Source/WebCore/html/OffscreenCanvas.h
    M Source/WebCore/html/canvas/CanvasRenderingContext.h
    M Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp
    M Source/WebCore/html/canvas/CanvasRenderingContext2DBase.h

  Log Message:
  -----------
  Refactor Canvas Post-Processing logic in CanvasBase
https://bugs.webkit.org/show_bug.cgi?id=255756
rdar://106872464

Reviewed by Kimmo Kinnunen.

When the noise injection policy is active, we are currently post-processing
Canvas2D pixel buffers, but that processing was not applied to WebGL image data
when alpha was premultiplied. This change fixes that bug by refactoring the
logic and moving it into CanvasBase. For Canvas2D, this patch tracks the dirty
rect from each drawing operation and only that area is post-processed before
Canvas image data is implicitly extracted (e.g., toDataURL). For WebGL, the
entire Canvas' image data is post-processed.

This patch leaves tracking CanvasRenderingContext2DBase::putImageData rects as
future work because those rects do not need post-processing.

* Source/WebCore/html/CanvasBase.cpp:
(WebCore::CanvasBase::makeRenderingResultsAvailable):
(WebCore::CanvasBase::didDraw): Here we now track the dirty area if we should
post-process the data in the future.

(WebCore::CanvasBase::shouldInjectNoiseBeforeReadback const):

(WebCore::CanvasBase::postProcessDirtyCanvasBuffer const):
(WebCore::CanvasBase::postProcessPixelBufferResults const):
(WebCore::CanvasBase::postProcessPixelBuffer const): Deleted.
These functions are moved and renamed from CanvasRenderingContext2DBase.

* Source/WebCore/html/CanvasBase.h:
(WebCore::CanvasBase::didDraw):
* Source/WebCore/html/CustomPaintCanvas.h:
* Source/WebCore/html/HTMLCanvasElement.cpp:
(WebCore::HTMLCanvasElement::didDraw):
(WebCore::HTMLCanvasElement::getImageData):
(WebCore::HTMLCanvasElement::setImageBufferAndMarkDirty):
* Source/WebCore/html/HTMLCanvasElement.h:
* Source/WebCore/html/OffscreenCanvas.cpp:
(WebCore::OffscreenCanvas::didDraw):
(WebCore::OffscreenCanvas::setImageBufferAndMarkDirty):
* Source/WebCore/html/OffscreenCanvas.h:
* Source/WebCore/html/canvas/CanvasRenderingContext.h:
(WebCore::CanvasRenderingContext::postProcessPixelBuffer const): Deleted.
* Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp:
(WebCore::computeImageDataRect):
(WebCore::CanvasRenderingContext2DBase::didDrawEntireCanvas):
(WebCore::CanvasRenderingContext2DBase::didDraw):
(WebCore::CanvasRenderingContext2DBase::getImageData const): Now this
function behaves in the same way as the other APIs that extract image data.

(WebCore::CanvasRenderingContext2DBase::putImageData):

(WebCore::CanvasRenderingContext2DBase::postProcessPixelBuffer const): Deleted.
This function is moved into CanvasBase.

* Source/WebCore/html/canvas/CanvasRenderingContext2DBase.h:
(WebCore::CanvasRenderingContext2DBase::didDraw):

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




More information about the webkit-changes mailing list