Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 921a80bb8d6adfbad24f3707282965b8b4080274
      
https://github.com/WebKit/WebKit/commit/921a80bb8d6adfbad24f3707282965b8b4080274
  Author: Gerald Squelart <[email protected]>
  Date:   2026-07-19 (Sun, 19 Jul 2026)

  Changed paths:
    M Source/WebCore/Headers.cmake
    M Source/WebCore/Sources.txt
    M Source/WebCore/WebCore.xcodeproj/project.pbxproj
    M Source/WebCore/html/ImageData.cpp
    M Source/WebCore/html/ImageDataArray.cpp
    M Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp
    A Source/WebCore/platform/graphics/ArrayPixelBuffer.cpp
    A Source/WebCore/platform/graphics/ArrayPixelBuffer.h
    M Source/WebCore/platform/graphics/PixelBuffer.cpp
    M Source/WebCore/platform/graphics/PixelBuffer.h
    M Source/WebCore/platform/graphics/TypedArrayPixelBuffer.cpp
    M Source/WebCore/platform/graphics/TypedArrayPixelBuffer.h
    M Source/WebKit/GPUProcess/graphics/ShareablePixelBuffer.h

  Log Message:
  -----------
  ArrayPixelBuffer superclass of TypedArrayPixelBuffer
https://bugs.webkit.org/show_bug.cgi?id=296971
rdar://157605644

Reviewed by Mike Wyrzykowski.

Currently PixelBuffer has 3 direct subclasses: ByteArrayPixelBuffer,
Float16ArrayPixelBuffer and ShareablePixelBuffer.

Byte- and Float16- have pretty much the same underlying storage: A
JavaScriptCore typed array, which is always a subclass of
JSC::ArrayBufferView. (But ShareablePixelBuffer is different.)

In some situations that only deal, or used to deal, with
ByteArrayPixelBuffer, we will want them to work with
Float16ArrayPixelBuffer as well.
Instead of doubling the code at each site, it would be best to use a
common base class that can abstract the differences in most cases, like
accessing the data as bytes.
But at the same time, we can't just use the current base PixelBuffer, as
we don't want to have to also deal with ShareablePixelBuffer, which
shouldn't happen in these code paths anyway.

So this introduces an intermediate abstract base class ArrayPixelBuffer
for these array-based concrete PixelBuffers.
Note that this abstract class ArrayPixelBuffer has non-virtual member
functions to access the data, so there is no penalty when calling them,
and the compiler could even inline them.

In summary, the class hierarchy is now as follows:
- PixelBuffer: Any kind of pixel buffer, this abstract base class
  stores the format, size, and a non-owning span to the data bytes.
- ShareablePixelBuffer: Concrete subclass owning a SharedMemory,
  with non-virtual data() to access that SharedMemory.
- ArrayPixelBuffer: Abstract subclass owning a JSC::ArrayBufferView,
  with non-virtual data() to access that JSC buffer. Useful for e.g.:
  canvas to cache putImageData pixels.
~ TypedArrayPixelBuffer: Templated concrete subclass, which
  guarantees by construction that the underlying data() is of a
  certain concrete type.
- ByteArrayPixelBuffer=Typed<JSC::Uint8ClampedArray>:
  Instantiation for byte-oriented buffers, useful for code that
  only deals with these, like BitmapImage.
- Float16ArrayPixelBuffer=Typed<JSC::Float16Array>: The newer
  intantiation to be used for HDR-capable elements.

Other improvements:
- Make leaf subclasses final.
- Make PixelBuffer member variables private for better encapsulation.
- Make PixelBuffer member variables const because they should never change.
- Make PixelBuffer::type() pure virtual, to ensure concrete subclasses
  override it.
- Qualify takeData() as `&&` to force object to be moved-from and catch
  potential use-after-move's.

* Source/WebCore/Headers.cmake:
* Source/WebCore/Sources.txt:
* Source/WebCore/WebCore.xcodeproj/project.pbxproj:
* Source/WebCore/html/ImageData.cpp:
(WebCore::ImageData::create):
* Source/WebCore/html/ImageDataArray.cpp:
(isType): Deleted.
* Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp:
(WebCore::CanvasRenderingContext2DBase::makeImageDataIfContentsCached const):
* Source/WebCore/platform/graphics/ArrayPixelBuffer.cpp: Added.
(WebCore::ArrayPixelBuffer::ArrayPixelBuffer):
* Source/WebCore/platform/graphics/ArrayPixelBuffer.h: Added.
(WebCore::ArrayPixelBuffer::takeData):
(isType):
* Source/WebCore/platform/graphics/PixelBuffer.cpp:
* Source/WebCore/platform/graphics/PixelBuffer.h:
(WebCore::PixelBuffer::type const): Deleted.
* Source/WebCore/platform/graphics/TypedArrayPixelBuffer.cpp:
(WebCore::>::TypedArrayPixelBuffer):
* Source/WebCore/platform/graphics/TypedArrayPixelBuffer.h:
* Source/WebKit/GPUProcess/graphics/ShareablePixelBuffer.h:
(WebKit::ShareablePixelBuffer::data const): Deleted.

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



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

Reply via email to