Diff
Modified: trunk/Source/WebCore/ChangeLog (267614 => 267615)
--- trunk/Source/WebCore/ChangeLog 2020-09-26 00:50:00 UTC (rev 267614)
+++ trunk/Source/WebCore/ChangeLog 2020-09-26 01:42:08 UTC (rev 267615)
@@ -1,3 +1,62 @@
+2020-09-25 Said Abou-Hallawa <[email protected]>
+
+ Move SerializationState from ImageBuffer to ImageBitmap
+ https://bugs.webkit.org/show_bug.cgi?id=216565
+
+ Reviewed by Kenneth Russell.
+
+ Introduce ImageBitmapBacking and make it a member of ImageBitmap. It
+ represents the backing store of an ImageBitmap. Currently it encapsulates
+ an ImageBuffer and the new enum SerializationState. In the future, it can
+ be extended to encapsulate either a texture or an ImageBuffer.
+
+ * Headers.cmake:
+ * Sources.txt:
+ * WebCore.xcodeproj/project.pbxproj:
+ * bindings/js/SerializedScriptValue.cpp:
+ (WebCore::CloneSerializer::dumpImageBitmap):
+ (WebCore::CloneDeserializer::deserialize):
+ (WebCore::CloneDeserializer::CloneDeserializer):
+ (WebCore::CloneDeserializer::readTransferredImageBitmap):
+ (WebCore::CloneDeserializer::readImageBitmap):
+ (WebCore::SerializedScriptValue::SerializedScriptValue):
+ (WebCore::SerializedScriptValue::computeMemoryCost const):
+ (WebCore::SerializedScriptValue::create):
+ (WebCore::SerializedScriptValue::deserialize):
+ * bindings/js/SerializedScriptValue.h:
+ (WebCore::SerializedScriptValue::SerializedScriptValue):
+ * html/ImageBitmap.cpp:
+ (WebCore::ImageBitmap::create):
+ (WebCore::ImageBitmap::detachBitmaps):
+ (WebCore::ImageBitmap::resolveWithBlankImageBuffer):
+ (WebCore::ImageBitmap::createPromise):
+ (WebCore::ImageBitmap::createFromBuffer):
+ (WebCore::ImageBitmap::ImageBitmap):
+ (WebCore::ImageBitmap::takeImageBitmapBacking):
+ (WebCore::ImageBitmap::takeImageBuffer):
+ (WebCore::ImageBitmap::width const): Deleted.
+ (WebCore::ImageBitmap::height const): Deleted.
+ (WebCore::ImageBitmap::close): Deleted.
+ (WebCore::ImageBitmap::transferOwnershipAndClose): Deleted.
+ * html/ImageBitmap.h:
+ * html/ImageBitmapBacking.cpp: Added.
+ (WebCore::ImageBitmapBacking::ImageBitmapBacking):
+ (WebCore::ImageBitmapBacking::buffer const):
+ (WebCore::ImageBitmapBacking::takeImageBuffer):
+ (WebCore::ImageBitmapBacking::width const):
+ (WebCore::ImageBitmapBacking::height const):
+ * html/ImageBitmapBacking.h: Added.
+ (WebCore::ImageBitmapBacking::originClean const):
+ (WebCore::ImageBitmapBacking::premultiplyAlpha const):
+ (WebCore::ImageBitmapBacking::forciblyPremultiplyAlpha const):
+ (WebCore::ImageBitmapBacking::serializationState const):
+ * html/OffscreenCanvas.cpp:
+ (WebCore::OffscreenCanvas::transferToImageBitmap):
+ * html/canvas/ImageBitmapRenderingContext.cpp:
+ (WebCore::ImageBitmapRenderingContext::setOutputBitmap):
+ * platform/graphics/ImageBuffer.h:
+ (): Deleted.
+
2020-09-25 Chris Dumez <[email protected]>
visibilitychange:hidden doesn't fire during page navigations
Modified: trunk/Source/WebCore/Headers.cmake (267614 => 267615)
--- trunk/Source/WebCore/Headers.cmake 2020-09-26 00:50:00 UTC (rev 267614)
+++ trunk/Source/WebCore/Headers.cmake 2020-09-26 01:42:08 UTC (rev 267615)
@@ -654,6 +654,7 @@
html/HTMLUnknownElement.h
html/HTMLVideoElement.h
html/ImageBitmap.h
+ html/ImageBitmapBacking.h
html/ImageData.h
html/ImageDocument.h
html/InputMode.h
Modified: trunk/Source/WebCore/Sources.txt (267614 => 267615)
--- trunk/Source/WebCore/Sources.txt 2020-09-26 00:50:00 UTC (rev 267614)
+++ trunk/Source/WebCore/Sources.txt 2020-09-26 01:42:08 UTC (rev 267615)
@@ -1194,6 +1194,7 @@
html/HTMLWBRElement.cpp
html/HiddenInputType.cpp
html/ImageBitmap.cpp
+html/ImageBitmapBacking.cpp
html/ImageData.cpp
html/ImageDocument.cpp
html/ImageInputType.cpp
Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (267614 => 267615)
--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2020-09-26 00:50:00 UTC (rev 267614)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2020-09-26 01:42:08 UTC (rev 267615)
@@ -2157,6 +2157,7 @@
71F05F802512442E0071E693 /* CSSPropertyAnimation.h in Headers */ = {isa = PBXBuildFile; fileRef = 71F05F7E2512440C0071E693 /* CSSPropertyAnimation.h */; settings = {ATTRIBUTES = (Private, ); }; };
72144333223EC8B000F12FF7 /* SVGProperty.h in Headers */ = {isa = PBXBuildFile; fileRef = 55EE5363223B2A2400FBA944 /* SVGProperty.h */; settings = {ATTRIBUTES = (Private, ); }; };
72144334223EC91600F12FF7 /* SVGPropertyOwner.h in Headers */ = {isa = PBXBuildFile; fileRef = 55EE5360223B2A2100FBA944 /* SVGPropertyOwner.h */; settings = {ATTRIBUTES = (Private, ); }; };
+ 721B49742512BA3B00FE9D3B /* ImageBitmapBacking.h in Headers */ = {isa = PBXBuildFile; fileRef = 721B49702512AC0400FE9D3B /* ImageBitmapBacking.h */; settings = {ATTRIBUTES = (Private, ); }; };
72283F0E230B268C00F5D828 /* ImagePaintingOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 72C18A3F230B04B7006847C7 /* ImagePaintingOptions.h */; settings = {ATTRIBUTES = (Private, ); }; };
724ED3321A3A8B2300F5F13C /* JSEXTBlendMinMax.h in Headers */ = {isa = PBXBuildFile; fileRef = 724ED3301A3A8B2300F5F13C /* JSEXTBlendMinMax.h */; };
724EE5501DC80D7F00A91FFB /* ActivityState.h in Headers */ = {isa = PBXBuildFile; fileRef = 724EE54E1DC7F25B00A91FFB /* ActivityState.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -9890,6 +9891,8 @@
71FF851822A3F81F005D5959 /* NavigatorMaxTouchPoints.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = NavigatorMaxTouchPoints.idl; sourceTree = "<group>"; };
721443452240C8BA00F12FF7 /* SVGAnimatedValueProperty.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SVGAnimatedValueProperty.h; sourceTree = "<group>"; };
721443462240CAD200F12FF7 /* SVGValueProperty.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SVGValueProperty.h; sourceTree = "<group>"; };
+ 721B496F2512AC0400FE9D3B /* ImageBitmapBacking.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = ImageBitmapBacking.cpp; sourceTree = "<group>"; };
+ 721B49702512AC0400FE9D3B /* ImageBitmapBacking.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ImageBitmapBacking.h; sourceTree = "<group>"; };
722A815C238FD50500C00583 /* AnimationFrameRate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AnimationFrameRate.h; sourceTree = "<group>"; };
724ED3291A3A7E5400F5F13C /* EXTBlendMinMax.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = EXTBlendMinMax.cpp; sourceTree = "<group>"; };
724ED32A1A3A7E5400F5F13C /* EXTBlendMinMax.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EXTBlendMinMax.h; sourceTree = "<group>"; };
@@ -23094,6 +23097,8 @@
31D26BC21F86D18C008FF255 /* ImageBitmap.cpp */,
31D26BBF1F86D189008FF255 /* ImageBitmap.h */,
31D26BC11F86D18B008FF255 /* ImageBitmap.idl */,
+ 721B496F2512AC0400FE9D3B /* ImageBitmapBacking.cpp */,
+ 721B49702512AC0400FE9D3B /* ImageBitmapBacking.h */,
31D26BC01F86D18A008FF255 /* ImageBitmapOptions.h */,
31D26BBD1F86D187008FF255 /* ImageBitmapOptions.idl */,
A77979130D6B9D0C003851B9 /* ImageData.cpp */,
@@ -31754,6 +31759,7 @@
B27535700B053814002CE64F /* Image.h in Headers */,
55A336F91D821E3C0022C4C7 /* ImageBackingStore.h in Headers */,
31815A311F9A6C8F00FCBF89 /* ImageBitmap.h in Headers */,
+ 721B49742512BA3B00FE9D3B /* ImageBitmapBacking.h in Headers */,
7C7903B31F86F95C00463A70 /* ImageBitmapRenderingContext.h in Headers */,
318EAD4D1FA91380008CEF86 /* ImageBitmapRenderingContextSettings.h in Headers */,
B2A10B920B3818BD00099AA4 /* ImageBuffer.h in Headers */,
Modified: trunk/Source/WebCore/bindings/js/SerializedScriptValue.cpp (267614 => 267615)
--- trunk/Source/WebCore/bindings/js/SerializedScriptValue.cpp 2020-09-26 00:50:00 UTC (rev 267614)
+++ trunk/Source/WebCore/bindings/js/SerializedScriptValue.cpp 2020-09-26 01:42:08 UTC (rev 267615)
@@ -35,6 +35,7 @@
#include "CryptoKeyRSAComponents.h"
#include "CryptoKeyRaw.h"
#include "IDBValue.h"
+#include "ImageBitmapBacking.h"
#include "JSBlob.h"
#include "JSCryptoKey.h"
#include "JSDOMBinding.h"
@@ -1043,9 +1044,7 @@
}
write(ImageBitmapTag);
- write(static_cast<uint8_t>(imageBitmap.originClean()));
- write(static_cast<uint8_t>(imageBitmap.premultiplyAlpha()));
- write(static_cast<uint8_t>(imageBitmap.forciblyPremultiplyAlpha()));
+ write(static_cast<uint8_t>(imageBitmap.serializationState().toRaw()));
write(static_cast<int32_t>(logicalSize.width()));
write(static_cast<int32_t>(logicalSize.height()));
write(static_cast<double>(buffer->resolutionScale()));
@@ -1931,7 +1930,7 @@
return str;
}
- static DeserializationResult deserialize(JSGlobalObject* lexicalGlobalObject, JSGlobalObject* globalObject, const Vector<RefPtr<MessagePort>>& messagePorts, Vector<std::pair<std::unique_ptr<ImageBuffer>, ImageBuffer::SerializationState>>&& imageBuffers
+ static DeserializationResult deserialize(JSGlobalObject* lexicalGlobalObject, JSGlobalObject* globalObject, const Vector<RefPtr<MessagePort>>& messagePorts, Vector<Optional<ImageBitmapBacking>>&& backingStores
#if ENABLE(OFFSCREEN_CANVAS)
, Vector<std::unique_ptr<DetachedOffscreenCanvas>>&& detachedOffscreenCanvases
#endif
@@ -1943,7 +1942,7 @@
{
if (!buffer.size())
return std::make_pair(jsNull(), SerializationReturnCode::UnspecifiedError);
- CloneDeserializer deserializer(lexicalGlobalObject, globalObject, messagePorts, arrayBufferContentsArray, buffer, blobURLs, blobFilePaths, sharedBuffers, WTFMove(imageBuffers)
+ CloneDeserializer deserializer(lexicalGlobalObject, globalObject, messagePorts, arrayBufferContentsArray, buffer, blobURLs, blobFilePaths, sharedBuffers, WTFMove(backingStores)
#if ENABLE(OFFSCREEN_CANVAS)
, WTFMove(detachedOffscreenCanvases)
#endif
@@ -1996,7 +1995,7 @@
size_t m_index;
};
- CloneDeserializer(JSGlobalObject* lexicalGlobalObject, JSGlobalObject* globalObject, const Vector<RefPtr<MessagePort>>& messagePorts, ArrayBufferContentsArray* arrayBufferContents, Vector<std::pair<std::unique_ptr<ImageBuffer>, ImageBuffer::SerializationState>>&& imageBuffers, const Vector<uint8_t>& buffer
+ CloneDeserializer(JSGlobalObject* lexicalGlobalObject, JSGlobalObject* globalObject, const Vector<RefPtr<MessagePort>>& messagePorts, ArrayBufferContentsArray* arrayBufferContents, Vector<Optional<ImageBitmapBacking>>&& backingStores, const Vector<uint8_t>& buffer
#if ENABLE(OFFSCREEN_CANVAS)
, Vector<std::unique_ptr<DetachedOffscreenCanvas>>&& detachedOffscreenCanvases = { }
#endif
@@ -2014,8 +2013,8 @@
, m_messagePorts(messagePorts)
, m_arrayBufferContents(arrayBufferContents)
, m_arrayBuffers(arrayBufferContents ? arrayBufferContents->size() : 0)
- , m_imageBuffers(WTFMove(imageBuffers))
- , m_imageBitmaps(m_imageBuffers.size())
+ , m_backingStores(WTFMove(backingStores))
+ , m_imageBitmaps(m_backingStores.size())
#if ENABLE(OFFSCREEN_CANVAS)
, m_detachedOffscreenCanvases(WTFMove(detachedOffscreenCanvases))
, m_offscreenCanvases(m_detachedOffscreenCanvases.size())
@@ -2028,7 +2027,7 @@
m_version = 0xFFFFFFFF;
}
- CloneDeserializer(JSGlobalObject* lexicalGlobalObject, JSGlobalObject* globalObject, const Vector<RefPtr<MessagePort>>& messagePorts, ArrayBufferContentsArray* arrayBufferContents, const Vector<uint8_t>& buffer, const Vector<String>& blobURLs, const Vector<String> blobFilePaths, ArrayBufferContentsArray* sharedBuffers, Vector<std::pair<std::unique_ptr<ImageBuffer>, ImageBuffer::SerializationState>>&& imageBuffers
+ CloneDeserializer(JSGlobalObject* lexicalGlobalObject, JSGlobalObject* globalObject, const Vector<RefPtr<MessagePort>>& messagePorts, ArrayBufferContentsArray* arrayBufferContents, const Vector<uint8_t>& buffer, const Vector<String>& blobURLs, const Vector<String> blobFilePaths, ArrayBufferContentsArray* sharedBuffers, Vector<Optional<ImageBitmapBacking>>&& backingStores
#if ENABLE(OFFSCREEN_CANVAS)
, Vector<std::unique_ptr<DetachedOffscreenCanvas>>&& detachedOffscreenCanvases
#endif
@@ -2049,8 +2048,8 @@
, m_blobURLs(blobURLs)
, m_blobFilePaths(blobFilePaths)
, m_sharedBuffers(sharedBuffers)
- , m_imageBuffers(WTFMove(imageBuffers))
- , m_imageBitmaps(m_imageBuffers.size())
+ , m_backingStores(WTFMove(backingStores))
+ , m_imageBitmaps(m_backingStores.size())
#if ENABLE(OFFSCREEN_CANVAS)
, m_detachedOffscreenCanvases(WTFMove(detachedOffscreenCanvases))
, m_offscreenCanvases(m_detachedOffscreenCanvases.size())
@@ -2883,13 +2882,13 @@
{
uint32_t index;
bool indexSuccessfullyRead = read(index);
- if (!indexSuccessfullyRead || index >= m_imageBuffers.size()) {
+ if (!indexSuccessfullyRead || index >= m_backingStores.size()) {
fail();
return JSValue();
}
if (!m_imageBitmaps[index])
- m_imageBitmaps[index] = ImageBitmap::create(WTFMove(m_imageBuffers.at(index)));
+ m_imageBitmaps[index] = ImageBitmap::create(WTFMove(m_backingStores.at(index)));
auto bitmap = m_imageBitmaps[index].get();
return getJSValue(bitmap);
@@ -2962,15 +2961,13 @@
JSValue readImageBitmap()
{
- uint8_t originClean;
- uint8_t premultiplyAlpha;
- uint8_t forciblyPremultiplyAlpha;
+ uint8_t serializationState;
int32_t logicalWidth;
int32_t logicalHeight;
double resolutionScale;
RefPtr<ArrayBuffer> arrayBuffer;
- if (!read(originClean) || !read(premultiplyAlpha) || !read(forciblyPremultiplyAlpha) || !read(logicalWidth) || !read(logicalHeight) || !read(resolutionScale) || !readArrayBuffer(arrayBuffer)) {
+ if (!read(serializationState) || !read(logicalWidth) || !read(logicalHeight) || !read(resolutionScale) || !readArrayBuffer(arrayBuffer)) {
fail();
return JSValue();
}
@@ -2999,7 +2996,7 @@
buffer->putImageData(AlphaPremultiplication::Premultiplied, *imageData, { IntPoint::zero(), logicalSize });
- auto bitmap = ImageBitmap::create({ WTFMove(buffer), ImageBuffer::SerializationState { static_cast<bool>(originClean), static_cast<bool>(premultiplyAlpha), static_cast<bool>(forciblyPremultiplyAlpha) }});
+ auto bitmap = ImageBitmap::create(ImageBitmapBacking(WTFMove(buffer), OptionSet<SerializationState>::fromRaw(serializationState)));
return getJSValue(bitmap);
}
@@ -3434,7 +3431,7 @@
Vector<String> m_blobURLs;
Vector<String> m_blobFilePaths;
ArrayBufferContentsArray* m_sharedBuffers;
- Vector<std::pair<std::unique_ptr<ImageBuffer>, ImageBuffer::SerializationState>> m_imageBuffers;
+ Vector<Optional<ImageBitmapBacking>> m_backingStores;
Vector<RefPtr<ImageBitmap>> m_imageBitmaps;
#if ENABLE(OFFSCREEN_CANVAS)
Vector<std::unique_ptr<DetachedOffscreenCanvas>> m_detachedOffscreenCanvases;
@@ -3658,7 +3655,7 @@
m_memoryCost = computeMemoryCost();
}
-SerializedScriptValue::SerializedScriptValue(Vector<uint8_t>&& buffer, const Vector<String>& blobURLs, std::unique_ptr<ArrayBufferContentsArray> arrayBufferContentsArray, std::unique_ptr<ArrayBufferContentsArray> sharedBufferContentsArray, Vector<std::pair<std::unique_ptr<ImageBuffer>, ImageBuffer::SerializationState>>&& imageBuffers
+SerializedScriptValue::SerializedScriptValue(Vector<uint8_t>&& buffer, const Vector<String>& blobURLs, std::unique_ptr<ArrayBufferContentsArray> arrayBufferContentsArray, std::unique_ptr<ArrayBufferContentsArray> sharedBufferContentsArray, Vector<Optional<ImageBitmapBacking>>&& backingStores
#if ENABLE(OFFSCREEN_CANVAS)
, Vector<std::unique_ptr<DetachedOffscreenCanvas>>&& detachedOffscreenCanvases
#endif
@@ -3669,7 +3666,7 @@
: m_data(WTFMove(buffer))
, m_arrayBufferContentsArray(WTFMove(arrayBufferContentsArray))
, m_sharedBufferContentsArray(WTFMove(sharedBufferContentsArray))
- , m_imageBuffers(WTFMove(imageBuffers))
+ , m_backingStores(WTFMove(backingStores))
#if ENABLE(OFFSCREEN_CANVAS)
, m_detachedOffscreenCanvases(WTFMove(detachedOffscreenCanvases))
#endif
@@ -3699,9 +3696,9 @@
cost += content.sizeInBytes();
}
- for (auto& pair : m_imageBuffers) {
- if (pair.first)
- cost += pair.first->memoryCost();
+ for (auto& backingStore : m_backingStores) {
+ if (auto buffer = backingStore ? backingStore->buffer() : nullptr)
+ cost += buffer->memoryCost();
}
#if ENABLE(OFFSCREEN_CANVAS)
@@ -3925,7 +3922,7 @@
if (arrayBufferContentsArray.hasException())
return arrayBufferContentsArray.releaseException();
- auto imageBuffers = ImageBitmap::detachBitmaps(WTFMove(imageBitmaps));
+ auto backingStores = ImageBitmap::detachBitmaps(WTFMove(imageBitmaps));
#if ENABLE(OFFSCREEN_CANVAS)
Vector<std::unique_ptr<DetachedOffscreenCanvas>> detachedCanvases;
@@ -3933,7 +3930,7 @@
detachedCanvases.append(offscreenCanvas->detach());
#endif
- return adoptRef(*new SerializedScriptValue(WTFMove(buffer), blobURLs, arrayBufferContentsArray.releaseReturnValue(), context == SerializationContext::WorkerPostMessage ? WTFMove(sharedBuffers) : nullptr, WTFMove(imageBuffers)
+ return adoptRef(*new SerializedScriptValue(WTFMove(buffer), blobURLs, arrayBufferContentsArray.releaseReturnValue(), context == SerializationContext::WorkerPostMessage ? WTFMove(sharedBuffers) : nullptr, WTFMove(backingStores)
#if ENABLE(OFFSCREEN_CANVAS)
, WTFMove(detachedCanvases)
#endif
@@ -3989,7 +3986,7 @@
JSValue SerializedScriptValue::deserialize(JSGlobalObject& lexicalGlobalObject, JSGlobalObject* globalObject, const Vector<RefPtr<MessagePort>>& messagePorts, const Vector<String>& blobURLs, const Vector<String>& blobFilePaths, SerializationErrorMode throwExceptions)
{
- DeserializationResult result = CloneDeserializer::deserialize(&lexicalGlobalObject, globalObject, messagePorts, WTFMove(m_imageBuffers)
+ DeserializationResult result = CloneDeserializer::deserialize(&lexicalGlobalObject, globalObject, messagePorts, WTFMove(m_backingStores)
#if ENABLE(OFFSCREEN_CANVAS)
, WTFMove(m_detachedOffscreenCanvases)
#endif
Modified: trunk/Source/WebCore/bindings/js/SerializedScriptValue.h (267614 => 267615)
--- trunk/Source/WebCore/bindings/js/SerializedScriptValue.h 2020-09-26 00:50:00 UTC (rev 267614)
+++ trunk/Source/WebCore/bindings/js/SerializedScriptValue.h 2020-09-26 01:42:08 UTC (rev 267615)
@@ -27,7 +27,6 @@
#pragma once
#include "ExceptionOr.h"
-#include "ImageBuffer.h"
#include <_javascript_Core/ArrayBuffer.h>
#include <_javascript_Core/JSCJSValue.h>
#include <_javascript_Core/Strong.h>
@@ -51,8 +50,8 @@
class DetachedOffscreenCanvas;
#endif
class IDBValue;
-class ImageBitmap;
class MessagePort;
+class ImageBitmapBacking;
class SharedBuffer;
enum class SerializationReturnCode;
@@ -117,7 +116,7 @@
private:
WEBCORE_EXPORT SerializedScriptValue(Vector<unsigned char>&&);
WEBCORE_EXPORT SerializedScriptValue(Vector<unsigned char>&&, std::unique_ptr<ArrayBufferContentsArray>);
- SerializedScriptValue(Vector<unsigned char>&&, const Vector<String>& blobURLs, std::unique_ptr<ArrayBufferContentsArray>, std::unique_ptr<ArrayBufferContentsArray> sharedBuffers, Vector<std::pair<std::unique_ptr<ImageBuffer>, ImageBuffer::SerializationState>>&& imageBuffers
+ SerializedScriptValue(Vector<unsigned char>&&, const Vector<String>& blobURLs, std::unique_ptr<ArrayBufferContentsArray>, std::unique_ptr<ArrayBufferContentsArray> sharedBuffers, Vector<Optional<ImageBitmapBacking>>&& backingStores
#if ENABLE(OFFSCREEN_CANVAS)
, Vector<std::unique_ptr<DetachedOffscreenCanvas>>&& = { }
#endif
@@ -131,7 +130,7 @@
Vector<unsigned char> m_data;
std::unique_ptr<ArrayBufferContentsArray> m_arrayBufferContentsArray;
std::unique_ptr<ArrayBufferContentsArray> m_sharedBufferContentsArray;
- Vector<std::pair<std::unique_ptr<ImageBuffer>, ImageBuffer::SerializationState>> m_imageBuffers;
+ Vector<Optional<ImageBitmapBacking>> m_backingStores;
#if ENABLE(OFFSCREEN_CANVAS)
Vector<std::unique_ptr<DetachedOffscreenCanvas>> m_detachedOffscreenCanvases;
#endif
Modified: trunk/Source/WebCore/html/ImageBitmap.cpp (267614 => 267615)
--- trunk/Source/WebCore/html/ImageBitmap.cpp 2020-09-26 00:50:00 UTC (rev 267614)
+++ trunk/Source/WebCore/html/ImageBitmap.cpp 2020-09-26 01:42:08 UTC (rev 267615)
@@ -69,23 +69,14 @@
Ref<ImageBitmap> ImageBitmap::create(IntSize size)
{
- return create(ImageBuffer::create(FloatSize(size.width(), size.height()), bufferRenderingMode));
+ return create({ ImageBuffer::create(FloatSize(size.width(), size.height()), bufferRenderingMode) });
}
-Ref<ImageBitmap> ImageBitmap::create(std::pair<std::unique_ptr<ImageBuffer>, ImageBuffer::SerializationState>&& buffer)
+Ref<ImageBitmap> ImageBitmap::create(Optional<ImageBitmapBacking>&& backingStore)
{
- auto imageBitmap = create(WTFMove(buffer.first));
- imageBitmap->m_originClean = buffer.second.originClean;
- imageBitmap->m_premultiplyAlpha = buffer.second.premultiplyAlpha;
- imageBitmap->m_forciblyPremultiplyAlpha = buffer.second.forciblyPremultiplyAlpha;
- return imageBitmap;
+ return adoptRef(*new ImageBitmap(WTFMove(backingStore)));
}
-Ref<ImageBitmap> ImageBitmap::create(std::unique_ptr<ImageBuffer>&& buffer)
-{
- return adoptRef(*new ImageBitmap(WTFMove(buffer)));
-}
-
void ImageBitmap::createPromise(ScriptExecutionContext& scriptExecutionContext, ImageBitmap::Source&& source, ImageBitmapOptions&& options, ImageBitmap::Promise&& promise)
{
WTF::switchOn(source,
@@ -95,15 +86,14 @@
);
}
-Vector<std::pair<std::unique_ptr<ImageBuffer>, ImageBuffer::SerializationState>> ImageBitmap::detachBitmaps(Vector<RefPtr<ImageBitmap>>&& bitmaps)
+Vector<Optional<ImageBitmapBacking>> ImageBitmap::detachBitmaps(Vector<RefPtr<ImageBitmap>>&& bitmaps)
{
- Vector<std::pair<std::unique_ptr<ImageBuffer>, ImageBuffer::SerializationState>> buffers;
+ Vector<Optional<ImageBitmapBacking>> buffers;
for (auto& bitmap : bitmaps)
- buffers.append(std::make_pair(bitmap->transferOwnershipAndClose(), ImageBuffer::SerializationState { bitmap->originClean(), bitmap->premultiplyAlpha(), bitmap->forciblyPremultiplyAlpha() }));
+ buffers.append(bitmap->takeImageBitmapBacking());
return buffers;
}
-
void ImageBitmap::createPromise(ScriptExecutionContext& scriptExecutionContext, ImageBitmap::Source&& source, ImageBitmapOptions&& options, int sx, int sy, int sw, int sh, ImageBitmap::Promise&& promise)
{
// 1. If either the sw or sh arguments are specified but zero, return a promise
@@ -243,13 +233,15 @@
// Resolve Promise with a blank 1x1 ImageBitmap.
auto bitmapData = ImageBuffer::create(FloatSize(1, 1), bufferRenderingMode);
- // 7. Create a new ImageBitmap object.
- auto imageBitmap = create(WTFMove(bitmapData));
-
// 9. If the origin of image's image is not the same origin as the origin specified by the
// entry settings object, then set the origin-clean flag of the ImageBitmap object's
// bitmap to false.
- imageBitmap->m_originClean = originClean;
+ OptionSet<SerializationState> serializationState;
+ if (originClean)
+ serializationState.add(SerializationState::OriginClean);
+
+ // 7. Create a new ImageBitmap object.
+ auto imageBitmap = create(ImageBitmapBacking(WTFMove(bitmapData), serializationState));
// 10. Return a new promise, but continue running these steps in parallel.
// 11. Resolve the promise with the new ImageBitmap object as the value.
@@ -373,16 +365,18 @@
FloatRect destRect(FloatPoint(), outputSize);
bitmapData->context().drawImage(*imageForRender, destRect, sourceRectangle.releaseReturnValue(), { interpolationQualityForResizeQuality(options.resizeQuality), imageOrientationForOrientation(options.imageOrientation) });
- // 7. Create a new ImageBitmap object.
- auto imageBitmap = create(WTFMove(bitmapData));
-
// 9. If the origin of image's image is not the same origin as the origin specified by the
// entry settings object, then set the origin-clean flag of the ImageBitmap object's
// bitmap to false.
+ OptionSet<SerializationState> serializationState;
+ if (!taintsOrigin(*cachedImage))
+ serializationState.add(SerializationState::OriginClean);
- imageBitmap->m_originClean = !taintsOrigin(*cachedImage);
+ if (alphaPremultiplicationForPremultiplyAlpha(options.premultiplyAlpha) == AlphaPremultiplication::Premultiplied)
+ serializationState.add(SerializationState::PremultiplyAlpha);
- imageBitmap->m_premultiplyAlpha = (alphaPremultiplicationForPremultiplyAlpha(options.premultiplyAlpha) == AlphaPremultiplication::Premultiplied);
+ // 7. Create a new ImageBitmap object.
+ auto imageBitmap = create(ImageBitmapBacking(WTFMove(bitmapData), serializationState));
// 10. Return a new promise, but continue running these steps in parallel.
// 11. Resolve the promise with the new ImageBitmap object as the value.
@@ -439,15 +433,17 @@
FloatRect destRect(FloatPoint(), outputSize);
bitmapData->context().drawImage(*imageForRender, destRect, sourceRectangle.releaseReturnValue(), { interpolationQualityForResizeQuality(options.resizeQuality), imageOrientationForOrientation(options.imageOrientation) });
- // 3. Create a new ImageBitmap object.
- auto imageBitmap = create(WTFMove(bitmapData));
-
// 5. Set the origin-clean flag of the ImageBitmap object's bitmap to the same value as
// the origin-clean flag of the canvas element's bitmap.
+ OptionSet<SerializationState> serializationState;
+ if (canvas.originClean())
+ serializationState.add(SerializationState::OriginClean);
- imageBitmap->m_originClean = canvas.originClean();
+ if (alphaPremultiplicationForPremultiplyAlpha(options.premultiplyAlpha) == AlphaPremultiplication::Premultiplied)
+ serializationState.add(SerializationState::PremultiplyAlpha);
- imageBitmap->m_premultiplyAlpha = (alphaPremultiplicationForPremultiplyAlpha(options.premultiplyAlpha) == AlphaPremultiplication::Premultiplied);
+ // 3. Create a new ImageBitmap object.
+ auto imageBitmap = create(ImageBitmapBacking(WTFMove(bitmapData), serializationState));
// 6. Return a new promise, but continue running these steps in parallel.
// 7. Resolve the promise with the new ImageBitmap object as the value.
@@ -514,16 +510,19 @@
video->paintCurrentFrameInContext(c, FloatRect(FloatPoint(), size));
}
- // 5. Let imageBitmap be a new ImageBitmap object.
- auto imageBitmap = create(WTFMove(bitmapData));
-
// 6.3. If the origin of image's video is not same origin with entry
// settings object's origin, then set the origin-clean flag of
// image's bitmap to false.
- imageBitmap->m_originClean = !taintsOrigin(scriptExecutionContext.securityOrigin(), *video);
+ OptionSet<SerializationState> serializationState;
+ if (!taintsOrigin(scriptExecutionContext.securityOrigin(), *video))
+ serializationState.add(SerializationState::OriginClean);
- imageBitmap->m_premultiplyAlpha = (alphaPremultiplicationForPremultiplyAlpha(options.premultiplyAlpha) == AlphaPremultiplication::Premultiplied);
+ if (alphaPremultiplicationForPremultiplyAlpha(options.premultiplyAlpha) == AlphaPremultiplication::Premultiplied)
+ serializationState.add(SerializationState::PremultiplyAlpha);
+ // 5. Let imageBitmap be a new ImageBitmap object.
+ auto imageBitmap = create(ImageBitmapBacking(WTFMove(bitmapData), serializationState));
+
// 6.4.1. Resolve p with imageBitmap.
promise.resolve(WTFMove(imageBitmap));
}
@@ -566,21 +565,25 @@
FloatRect destRect(FloatPoint(), outputSize);
bitmapData->context().drawImage(*imageForRender, destRect, sourceRectangle.releaseReturnValue(), { interpolationQualityForResizeQuality(options.resizeQuality), imageOrientationForOrientation(options.imageOrientation) });
- // 3. Create a new ImageBitmap object.
- auto imageBitmap = create(WTFMove(bitmapData));
-
// 5. Set the origin-clean flag of the ImageBitmap object's bitmap to the same
// value as the origin-clean flag of the bitmap of the image argument.
- imageBitmap->m_originClean = existingImageBitmap->originClean();
+ OptionSet<SerializationState> serializationState;
+ if (existingImageBitmap->originClean())
+ serializationState.add(SerializationState::OriginClean);
- imageBitmap->m_premultiplyAlpha = (alphaPremultiplicationForPremultiplyAlpha(options.premultiplyAlpha) == AlphaPremultiplication::Premultiplied);
+ if (alphaPremultiplicationForPremultiplyAlpha(options.premultiplyAlpha) == AlphaPremultiplication::Premultiplied) {
+ serializationState.add(SerializationState::PremultiplyAlpha);
- // At least in the Core Graphics backend, when creating an ImageBitmap from
- // an ImageBitmap, the alpha channel of bitmapData isn't premultiplied even
- // though the alpha mode of the internal surface claims it is. Instruct
- // users of this ImageBitmap to ignore the internal surface's alpha mode.
- imageBitmap->m_forciblyPremultiplyAlpha = imageBitmap->m_premultiplyAlpha;
+ // At least in the Core Graphics backend, when creating an ImageBitmap from
+ // an ImageBitmap, the alpha channel of bitmapData isn't premultiplied even
+ // though the alpha mode of the internal surface claims it is. Instruct
+ // users of this ImageBitmap to ignore the internal surface's alpha mode.
+ serializationState.add(SerializationState::ForciblyPremultiplyAlpha);
+ }
+ // 3. Create a new ImageBitmap object.
+ auto imageBitmap = create(ImageBitmapBacking(WTFMove(bitmapData), serializationState));
+
// 6. Return a new promise, but continue running these steps in parallel.
// 7. Resolve the promise with the new ImageBitmap object as the value.
promise.resolve(WTFMove(imageBitmap));
@@ -752,9 +755,11 @@
FloatRect destRect(FloatPoint(), outputSize);
bitmapData->context().drawImage(*image, destRect, sourceRectangle.releaseReturnValue(), { interpolationQualityForResizeQuality(options.resizeQuality), imageOrientationForOrientation(options.imageOrientation) });
- auto imageBitmap = create(WTFMove(bitmapData));
+ OptionSet<SerializationState> serializationState = SerializationState::OriginClean;
+ if (alphaPremultiplicationForPremultiplyAlpha(options.premultiplyAlpha) == AlphaPremultiplication::Premultiplied)
+ serializationState.add(SerializationState::PremultiplyAlpha);
- imageBitmap->m_premultiplyAlpha = (alphaPremultiplicationForPremultiplyAlpha(options.premultiplyAlpha) == AlphaPremultiplication::Premultiplied);
+ auto imageBitmap = create(ImageBitmapBacking(WTFMove(bitmapData), serializationState));
promise.resolve(WTFMove(imageBitmap));
}
@@ -799,7 +804,7 @@
&& sourceRectangle.returnValue().size() == outputSize
&& options.imageOrientation == ImageBitmapOptions::Orientation::None) {
bitmapData->putImageData(AlphaPremultiplication::Unpremultiplied, *imageData, sourceRectangle.releaseReturnValue(), { }, alphaPremultiplication);
- auto imageBitmap = create(WTFMove(bitmapData));
+ auto imageBitmap = create(ImageBitmapBacking(WTFMove(bitmapData)));
// The result is implicitly origin-clean, and alpha premultiplication has already been handled.
promise.resolve(WTFMove(imageBitmap));
return;
@@ -813,47 +818,30 @@
bitmapData->context().drawImageBuffer(*tempBitmapData, destRect, sourceRectangle.releaseReturnValue(), { interpolationQualityForResizeQuality(options.resizeQuality), imageOrientationForOrientation(options.imageOrientation) });
// 6.4.1. Resolve p with ImageBitmap.
- auto imageBitmap = create(WTFMove(bitmapData));
+ auto imageBitmap = create({ WTFMove(bitmapData) });
// The result is implicitly origin-clean, and alpha premultiplication has already been handled.
promise.resolve(WTFMove(imageBitmap));
}
-ImageBitmap::ImageBitmap(std::unique_ptr<ImageBuffer>&& buffer)
- : m_bitmapData(WTFMove(buffer))
+ImageBitmap::ImageBitmap(Optional<ImageBitmapBacking>&& backingStore)
+ : m_backingStore(WTFMove(backingStore))
{
- ASSERT(m_bitmapData);
+ ASSERT_IMPLIES(m_backingStore, m_backingStore->buffer());
}
ImageBitmap::~ImageBitmap() = default;
-unsigned ImageBitmap::width() const
+Optional<ImageBitmapBacking> ImageBitmap::takeImageBitmapBacking()
{
- if (m_detached || !m_bitmapData)
- return 0;
-
- // FIXME: Is this the right width?
- return m_bitmapData->logicalSize().width();
+ return std::exchange(m_backingStore, WTF::nullopt);
}
-unsigned ImageBitmap::height() const
+std::unique_ptr<ImageBuffer> ImageBitmap::takeImageBuffer()
{
- if (m_detached || !m_bitmapData)
- return 0;
-
- // FIXME: Is this the right height?
- return m_bitmapData->logicalSize().height();
+ if (auto backingStore = takeImageBitmapBacking())
+ return backingStore->takeImageBuffer();
+ ASSERT(isDetached());
+ return nullptr;
}
-void ImageBitmap::close()
-{
- m_detached = true;
- m_bitmapData = nullptr;
-}
-
-std::unique_ptr<ImageBuffer> ImageBitmap::transferOwnershipAndClose()
-{
- m_detached = true;
- return WTFMove(m_bitmapData);
-}
-
-}
+} // namespace WebCore
Modified: trunk/Source/WebCore/html/ImageBitmap.h (267614 => 267615)
--- trunk/Source/WebCore/html/ImageBitmap.h 2020-09-26 00:50:00 UTC (rev 267614)
+++ trunk/Source/WebCore/html/ImageBitmap.h 2020-09-26 01:42:08 UTC (rev 267615)
@@ -26,7 +26,7 @@
#pragma once
#include "IDLTypes.h"
-#include "ImageBuffer.h"
+#include "ImageBitmapBacking.h"
#include "ScriptWrappable.h"
#include <wtf/RefCounted.h>
@@ -83,38 +83,34 @@
static void createPromise(ScriptExecutionContext&, Source&&, ImageBitmapOptions&&, int sx, int sy, int sw, int sh, Promise&&);
static Ref<ImageBitmap> create(IntSize);
- static Ref<ImageBitmap> create(std::pair<std::unique_ptr<ImageBuffer>, ImageBuffer::SerializationState>&&);
+ static Ref<ImageBitmap> create(Optional<ImageBitmapBacking>&&);
~ImageBitmap();
- unsigned width() const;
- unsigned height() const;
- void close();
+ ImageBuffer* buffer() const { return m_backingStore ? m_backingStore->buffer() : nullptr; }
+ // This function has the implicit side-effect of detaching the backing store.
+ // It returns nullptr if the ImageBitmap's already detached.
+ std::unique_ptr<ImageBuffer> takeImageBuffer();
+ OptionSet<SerializationState> serializationState() const { return m_backingStore ? m_backingStore->serializationState() : SerializationState(); }
- bool isDetached() const { return m_detached; }
+ unsigned width() const { return m_backingStore ? m_backingStore->width() : 0; }
+ unsigned height() const { return m_backingStore ? m_backingStore->height() : 0; }
- ImageBuffer* buffer() { return m_bitmapData.get(); }
+ bool originClean() const { return m_backingStore && m_backingStore->originClean(); }
+ bool premultiplyAlpha() const { return m_backingStore && m_backingStore->premultiplyAlpha(); }
+ bool forciblyPremultiplyAlpha() const { return m_backingStore && m_backingStore->forciblyPremultiplyAlpha(); }
- bool originClean() const { return m_originClean; }
+ Optional<ImageBitmapBacking> takeImageBitmapBacking();
+ bool isDetached() const { return !m_backingStore.hasValue(); }
+ void close() { takeImageBitmapBacking(); }
- bool premultiplyAlpha() const { return m_premultiplyAlpha; }
+ static Vector<Optional<ImageBitmapBacking>> detachBitmaps(Vector<RefPtr<ImageBitmap>>&&);
- // When WebGL consumes an Image coming from an ImageBitmap's ImageBuffer, it typically honors
- // the alpha mode of that native image - CGImageAlphaInfo in the Core Graphics backend. For
- // ImageBitmaps created from ImageBitmaps, this information is not accurate, and callers must be
- // told to ignore the alpha mode, and forcibly premultiply the alpha channel.
- bool forciblyPremultiplyAlpha() const { return m_forciblyPremultiplyAlpha; }
-
- std::unique_ptr<ImageBuffer> transferOwnershipAndClose();
-
- static Vector<std::pair<std::unique_ptr<ImageBuffer>, ImageBuffer::SerializationState>> detachBitmaps(Vector<RefPtr<ImageBitmap>>&&);
-
private:
friend class ImageBitmapImageObserver;
friend class PendingImageBitmap;
- static Ref<ImageBitmap> create(std::unique_ptr<ImageBuffer>&&);
- ImageBitmap(std::unique_ptr<ImageBuffer>&&);
+ ImageBitmap(Optional<ImageBitmapBacking>&&);
static void resolveWithBlankImageBuffer(bool originClean, Promise&&);
@@ -133,11 +129,7 @@
static void createPromise(ScriptExecutionContext&, RefPtr<TypedOMCSSImageValue>&, ImageBitmapOptions&&, Optional<IntRect>, Promise&&);
static void createFromBuffer(Ref<ArrayBuffer>&&, String mimeType, long long expectedContentLength, const URL&, ImageBitmapOptions&&, Optional<IntRect>, Promise&&);
- std::unique_ptr<ImageBuffer> m_bitmapData;
- bool m_detached { false };
- bool m_originClean { true };
- bool m_premultiplyAlpha { false };
- bool m_forciblyPremultiplyAlpha { false };
+ Optional<ImageBitmapBacking> m_backingStore;
};
}
Added: trunk/Source/WebCore/html/ImageBitmapBacking.cpp (0 => 267615)
--- trunk/Source/WebCore/html/ImageBitmapBacking.cpp (rev 0)
+++ trunk/Source/WebCore/html/ImageBitmapBacking.cpp 2020-09-26 01:42:08 UTC (rev 267615)
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2020 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "ImageBitmapBacking.h"
+
+namespace WebCore {
+
+ImageBitmapBacking::ImageBitmapBacking(std::unique_ptr<ImageBuffer>&& bitmapData, OptionSet<SerializationState> serializationState)
+ : m_bitmapData(WTFMove(bitmapData))
+ , m_serializationState(serializationState)
+{
+ ASSERT(m_bitmapData);
+}
+
+ImageBuffer* ImageBitmapBacking::buffer() const
+{
+ return m_bitmapData.get();
+}
+
+std::unique_ptr<ImageBuffer> ImageBitmapBacking::takeImageBuffer()
+{
+ return WTFMove(m_bitmapData);
+}
+
+unsigned ImageBitmapBacking::width() const
+{
+ // FIXME: Is this the right width?
+ return m_bitmapData ? m_bitmapData->logicalSize().width() : 0;
+}
+
+unsigned ImageBitmapBacking::height() const
+{
+ // FIXME: Is this the right height?
+ return m_bitmapData ? m_bitmapData->logicalSize().height() : 0;
+}
+
+} // namespace WebCore
Added: trunk/Source/WebCore/html/ImageBitmapBacking.h (0 => 267615)
--- trunk/Source/WebCore/html/ImageBitmapBacking.h (rev 0)
+++ trunk/Source/WebCore/html/ImageBitmapBacking.h 2020-09-26 01:42:08 UTC (rev 267615)
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2020 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include "ImageBuffer.h"
+#include <wtf/OptionSet.h>
+
+namespace WebCore {
+
+enum class SerializationState : uint8_t {
+ OriginClean = 1 << 0,
+ PremultiplyAlpha = 1 << 1,
+ ForciblyPremultiplyAlpha = 1 << 2
+};
+
+class ImageBitmapBacking {
+public:
+ ImageBitmapBacking(std::unique_ptr<ImageBuffer>&&, OptionSet<SerializationState> = SerializationState::OriginClean);
+
+ ImageBuffer* buffer() const;
+ std::unique_ptr<ImageBuffer> takeImageBuffer();
+
+ unsigned width() const;
+ unsigned height() const;
+
+ bool originClean() const { return m_serializationState.contains(SerializationState::OriginClean); }
+
+ bool premultiplyAlpha() const { return m_serializationState.contains(SerializationState::PremultiplyAlpha); }
+ // When WebGL consumes an Image coming from an ImageBitmap's ImageBuffer, it typically honors
+ // the alpha mode of that native image - CGImageAlphaInfo in the Core Graphics backend. For
+ // ImageBitmaps created from ImageBitmaps, this information is not accurate, and callers must be
+ // told to ignore the alpha mode, and forcibly premultiply the alpha channel.
+ bool forciblyPremultiplyAlpha() const { return m_serializationState.contains(SerializationState::ForciblyPremultiplyAlpha); }
+
+ OptionSet<SerializationState> serializationState() const { return m_serializationState; }
+
+private:
+ std::unique_ptr<ImageBuffer> m_bitmapData;
+ OptionSet<SerializationState> m_serializationState;
+};
+
+} // namespace WebCore
Modified: trunk/Source/WebCore/html/OffscreenCanvas.cpp (267614 => 267615)
--- trunk/Source/WebCore/html/OffscreenCanvas.cpp 2020-09-26 00:50:00 UTC (rev 267614)
+++ trunk/Source/WebCore/html/OffscreenCanvas.cpp 2020-09-26 01:42:08 UTC (rev 267615)
@@ -250,13 +250,13 @@
return { RefPtr<ImageBitmap> { nullptr } };
if (!m_hasCreatedImageBuffer)
- return { ImageBitmap::create({ ImageBuffer::create(size(), RenderingMode::Unaccelerated), ImageBuffer::SerializationState { true, false, false }}) };
+ return { ImageBitmap::create(ImageBitmapBacking(ImageBuffer::create(size(), RenderingMode::Unaccelerated))) };
auto buffer = takeImageBuffer();
if (!buffer)
return { RefPtr<ImageBitmap> { nullptr } };
- return { ImageBitmap::create({ WTFMove(buffer), ImageBuffer::SerializationState { originClean(), false, false }}) };
+ return { ImageBitmap::create(ImageBitmapBacking(WTFMove(buffer), originClean() ? SerializationState::OriginClean : SerializationState())) };
}
#if ENABLE(WEBGL)
Modified: trunk/Source/WebCore/html/canvas/ImageBitmapRenderingContext.cpp (267614 => 267615)
--- trunk/Source/WebCore/html/canvas/ImageBitmapRenderingContext.cpp 2020-09-26 00:50:00 UTC (rev 267614)
+++ trunk/Source/WebCore/html/canvas/ImageBitmapRenderingContext.cpp 2020-09-26 01:42:08 UTC (rev 267615)
@@ -117,7 +117,7 @@
canvas()->setOriginClean();
else
canvas()->setOriginTainted();
- canvas()->setImageBufferAndMarkDirty(imageBitmap->transferOwnershipAndClose());
+ canvas()->setImageBufferAndMarkDirty(imageBitmap->takeImageBuffer());
}
ExceptionOr<void> ImageBitmapRenderingContext::transferFromImageBitmap(RefPtr<ImageBitmap> imageBitmap)
Modified: trunk/Source/WebCore/platform/graphics/ImageBuffer.h (267614 => 267615)
--- trunk/Source/WebCore/platform/graphics/ImageBuffer.h 2020-09-26 00:50:00 UTC (rev 267614)
+++ trunk/Source/WebCore/platform/graphics/ImageBuffer.h 2020-09-26 01:42:08 UTC (rev 267615)
@@ -38,12 +38,6 @@
class ImageBuffer {
public:
- struct SerializationState {
- bool originClean { false };
- bool premultiplyAlpha { false };
- bool forciblyPremultiplyAlpha { false };
- };
-
// Will return a null pointer on allocation failure.
WEBCORE_EXPORT static std::unique_ptr<ImageBuffer> create(const FloatSize&, ShouldAccelerate, ShouldUseDisplayList, RenderingPurpose, float resolutionScale = 1, ColorSpace = ColorSpace::SRGB, const HostWindow* = nullptr);
WEBCORE_EXPORT static std::unique_ptr<ImageBuffer> create(const FloatSize&, RenderingMode, float resolutionScale = 1, ColorSpace = ColorSpace::SRGB, const HostWindow* = nullptr);