Changeset 267615 in webkit
- Timestamp:
- Sep 25, 2020, 6:42:08 PM (6 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 2 added
- 11 edited
-
ChangeLog (modified) (1 diff)
-
Headers.cmake (modified) (1 diff)
-
Sources.txt (modified) (1 diff)
-
WebCore.xcodeproj/project.pbxproj (modified) (4 diffs)
-
bindings/js/SerializedScriptValue.cpp (modified) (20 diffs)
-
bindings/js/SerializedScriptValue.h (modified) (4 diffs)
-
html/ImageBitmap.cpp (modified) (10 diffs)
-
html/ImageBitmap.h (modified) (4 diffs)
-
html/ImageBitmapBacking.cpp (added)
-
html/ImageBitmapBacking.h (added)
-
html/OffscreenCanvas.cpp (modified) (2 diffs)
-
html/canvas/ImageBitmapRenderingContext.cpp (modified) (1 diff)
-
platform/graphics/ImageBuffer.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r267614 r267615 1 2020-09-25 Said Abou-Hallawa <sabouhallawa@apple.com> 2 3 Move SerializationState from ImageBuffer to ImageBitmap 4 https://bugs.webkit.org/show_bug.cgi?id=216565 5 6 Reviewed by Kenneth Russell. 7 8 Introduce ImageBitmapBacking and make it a member of ImageBitmap. It 9 represents the backing store of an ImageBitmap. Currently it encapsulates 10 an ImageBuffer and the new enum SerializationState. In the future, it can 11 be extended to encapsulate either a texture or an ImageBuffer. 12 13 * Headers.cmake: 14 * Sources.txt: 15 * WebCore.xcodeproj/project.pbxproj: 16 * bindings/js/SerializedScriptValue.cpp: 17 (WebCore::CloneSerializer::dumpImageBitmap): 18 (WebCore::CloneDeserializer::deserialize): 19 (WebCore::CloneDeserializer::CloneDeserializer): 20 (WebCore::CloneDeserializer::readTransferredImageBitmap): 21 (WebCore::CloneDeserializer::readImageBitmap): 22 (WebCore::SerializedScriptValue::SerializedScriptValue): 23 (WebCore::SerializedScriptValue::computeMemoryCost const): 24 (WebCore::SerializedScriptValue::create): 25 (WebCore::SerializedScriptValue::deserialize): 26 * bindings/js/SerializedScriptValue.h: 27 (WebCore::SerializedScriptValue::SerializedScriptValue): 28 * html/ImageBitmap.cpp: 29 (WebCore::ImageBitmap::create): 30 (WebCore::ImageBitmap::detachBitmaps): 31 (WebCore::ImageBitmap::resolveWithBlankImageBuffer): 32 (WebCore::ImageBitmap::createPromise): 33 (WebCore::ImageBitmap::createFromBuffer): 34 (WebCore::ImageBitmap::ImageBitmap): 35 (WebCore::ImageBitmap::takeImageBitmapBacking): 36 (WebCore::ImageBitmap::takeImageBuffer): 37 (WebCore::ImageBitmap::width const): Deleted. 38 (WebCore::ImageBitmap::height const): Deleted. 39 (WebCore::ImageBitmap::close): Deleted. 40 (WebCore::ImageBitmap::transferOwnershipAndClose): Deleted. 41 * html/ImageBitmap.h: 42 * html/ImageBitmapBacking.cpp: Added. 43 (WebCore::ImageBitmapBacking::ImageBitmapBacking): 44 (WebCore::ImageBitmapBacking::buffer const): 45 (WebCore::ImageBitmapBacking::takeImageBuffer): 46 (WebCore::ImageBitmapBacking::width const): 47 (WebCore::ImageBitmapBacking::height const): 48 * html/ImageBitmapBacking.h: Added. 49 (WebCore::ImageBitmapBacking::originClean const): 50 (WebCore::ImageBitmapBacking::premultiplyAlpha const): 51 (WebCore::ImageBitmapBacking::forciblyPremultiplyAlpha const): 52 (WebCore::ImageBitmapBacking::serializationState const): 53 * html/OffscreenCanvas.cpp: 54 (WebCore::OffscreenCanvas::transferToImageBitmap): 55 * html/canvas/ImageBitmapRenderingContext.cpp: 56 (WebCore::ImageBitmapRenderingContext::setOutputBitmap): 57 * platform/graphics/ImageBuffer.h: 58 (): Deleted. 59 1 60 2020-09-25 Chris Dumez <cdumez@apple.com> 2 61 -
trunk/Source/WebCore/Headers.cmake
r267576 r267615 655 655 html/HTMLVideoElement.h 656 656 html/ImageBitmap.h 657 html/ImageBitmapBacking.h 657 658 html/ImageData.h 658 659 html/ImageDocument.h -
trunk/Source/WebCore/Sources.txt
r267613 r267615 1195 1195 html/HiddenInputType.cpp 1196 1196 html/ImageBitmap.cpp 1197 html/ImageBitmapBacking.cpp 1197 1198 html/ImageData.cpp 1198 1199 html/ImageDocument.cpp -
trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj
r267613 r267615 2158 2158 72144333223EC8B000F12FF7 /* SVGProperty.h in Headers */ = {isa = PBXBuildFile; fileRef = 55EE5363223B2A2400FBA944 /* SVGProperty.h */; settings = {ATTRIBUTES = (Private, ); }; }; 2159 2159 72144334223EC91600F12FF7 /* SVGPropertyOwner.h in Headers */ = {isa = PBXBuildFile; fileRef = 55EE5360223B2A2100FBA944 /* SVGPropertyOwner.h */; settings = {ATTRIBUTES = (Private, ); }; }; 2160 721B49742512BA3B00FE9D3B /* ImageBitmapBacking.h in Headers */ = {isa = PBXBuildFile; fileRef = 721B49702512AC0400FE9D3B /* ImageBitmapBacking.h */; settings = {ATTRIBUTES = (Private, ); }; }; 2160 2161 72283F0E230B268C00F5D828 /* ImagePaintingOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 72C18A3F230B04B7006847C7 /* ImagePaintingOptions.h */; settings = {ATTRIBUTES = (Private, ); }; }; 2161 2162 724ED3321A3A8B2300F5F13C /* JSEXTBlendMinMax.h in Headers */ = {isa = PBXBuildFile; fileRef = 724ED3301A3A8B2300F5F13C /* JSEXTBlendMinMax.h */; }; … … 9891 9892 721443452240C8BA00F12FF7 /* SVGAnimatedValueProperty.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SVGAnimatedValueProperty.h; sourceTree = "<group>"; }; 9892 9893 721443462240CAD200F12FF7 /* SVGValueProperty.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SVGValueProperty.h; sourceTree = "<group>"; }; 9894 721B496F2512AC0400FE9D3B /* ImageBitmapBacking.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = ImageBitmapBacking.cpp; sourceTree = "<group>"; }; 9895 721B49702512AC0400FE9D3B /* ImageBitmapBacking.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ImageBitmapBacking.h; sourceTree = "<group>"; }; 9893 9896 722A815C238FD50500C00583 /* AnimationFrameRate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AnimationFrameRate.h; sourceTree = "<group>"; }; 9894 9897 724ED3291A3A7E5400F5F13C /* EXTBlendMinMax.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = EXTBlendMinMax.cpp; sourceTree = "<group>"; }; … … 23095 23098 31D26BBF1F86D189008FF255 /* ImageBitmap.h */, 23096 23099 31D26BC11F86D18B008FF255 /* ImageBitmap.idl */, 23100 721B496F2512AC0400FE9D3B /* ImageBitmapBacking.cpp */, 23101 721B49702512AC0400FE9D3B /* ImageBitmapBacking.h */, 23097 23102 31D26BC01F86D18A008FF255 /* ImageBitmapOptions.h */, 23098 23103 31D26BBD1F86D187008FF255 /* ImageBitmapOptions.idl */, … … 31755 31760 55A336F91D821E3C0022C4C7 /* ImageBackingStore.h in Headers */, 31756 31761 31815A311F9A6C8F00FCBF89 /* ImageBitmap.h in Headers */, 31762 721B49742512BA3B00FE9D3B /* ImageBitmapBacking.h in Headers */, 31757 31763 7C7903B31F86F95C00463A70 /* ImageBitmapRenderingContext.h in Headers */, 31758 31764 318EAD4D1FA91380008CEF86 /* ImageBitmapRenderingContextSettings.h in Headers */, -
trunk/Source/WebCore/bindings/js/SerializedScriptValue.cpp
r267373 r267615 36 36 #include "CryptoKeyRaw.h" 37 37 #include "IDBValue.h" 38 #include "ImageBitmapBacking.h" 38 39 #include "JSBlob.h" 39 40 #include "JSCryptoKey.h" … … 1044 1045 1045 1046 write(ImageBitmapTag); 1046 write(static_cast<uint8_t>(imageBitmap.originClean())); 1047 write(static_cast<uint8_t>(imageBitmap.premultiplyAlpha())); 1048 write(static_cast<uint8_t>(imageBitmap.forciblyPremultiplyAlpha())); 1047 write(static_cast<uint8_t>(imageBitmap.serializationState().toRaw())); 1049 1048 write(static_cast<int32_t>(logicalSize.width())); 1050 1049 write(static_cast<int32_t>(logicalSize.height())); … … 1932 1931 } 1933 1932 1934 static DeserializationResult deserialize(JSGlobalObject* lexicalGlobalObject, JSGlobalObject* globalObject, const Vector<RefPtr<MessagePort>>& messagePorts, Vector< std::pair<std::unique_ptr<ImageBuffer>, ImageBuffer::SerializationState>>&& imageBuffers1933 static DeserializationResult deserialize(JSGlobalObject* lexicalGlobalObject, JSGlobalObject* globalObject, const Vector<RefPtr<MessagePort>>& messagePorts, Vector<Optional<ImageBitmapBacking>>&& backingStores 1935 1934 #if ENABLE(OFFSCREEN_CANVAS) 1936 1935 , Vector<std::unique_ptr<DetachedOffscreenCanvas>>&& detachedOffscreenCanvases … … 1944 1943 if (!buffer.size()) 1945 1944 return std::make_pair(jsNull(), SerializationReturnCode::UnspecifiedError); 1946 CloneDeserializer deserializer(lexicalGlobalObject, globalObject, messagePorts, arrayBufferContentsArray, buffer, blobURLs, blobFilePaths, sharedBuffers, WTFMove( imageBuffers)1945 CloneDeserializer deserializer(lexicalGlobalObject, globalObject, messagePorts, arrayBufferContentsArray, buffer, blobURLs, blobFilePaths, sharedBuffers, WTFMove(backingStores) 1947 1946 #if ENABLE(OFFSCREEN_CANVAS) 1948 1947 , WTFMove(detachedOffscreenCanvases) … … 1997 1996 }; 1998 1997 1999 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>& buffer1998 CloneDeserializer(JSGlobalObject* lexicalGlobalObject, JSGlobalObject* globalObject, const Vector<RefPtr<MessagePort>>& messagePorts, ArrayBufferContentsArray* arrayBufferContents, Vector<Optional<ImageBitmapBacking>>&& backingStores, const Vector<uint8_t>& buffer 2000 1999 #if ENABLE(OFFSCREEN_CANVAS) 2001 2000 , Vector<std::unique_ptr<DetachedOffscreenCanvas>>&& detachedOffscreenCanvases = { } … … 2015 2014 , m_arrayBufferContents(arrayBufferContents) 2016 2015 , m_arrayBuffers(arrayBufferContents ? arrayBufferContents->size() : 0) 2017 , m_ imageBuffers(WTFMove(imageBuffers))2018 , m_imageBitmaps(m_ imageBuffers.size())2016 , m_backingStores(WTFMove(backingStores)) 2017 , m_imageBitmaps(m_backingStores.size()) 2019 2018 #if ENABLE(OFFSCREEN_CANVAS) 2020 2019 , m_detachedOffscreenCanvases(WTFMove(detachedOffscreenCanvases)) … … 2029 2028 } 2030 2029 2031 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>>&& imageBuffers2030 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 2032 2031 #if ENABLE(OFFSCREEN_CANVAS) 2033 2032 , Vector<std::unique_ptr<DetachedOffscreenCanvas>>&& detachedOffscreenCanvases … … 2050 2049 , m_blobFilePaths(blobFilePaths) 2051 2050 , m_sharedBuffers(sharedBuffers) 2052 , m_ imageBuffers(WTFMove(imageBuffers))2053 , m_imageBitmaps(m_ imageBuffers.size())2051 , m_backingStores(WTFMove(backingStores)) 2052 , m_imageBitmaps(m_backingStores.size()) 2054 2053 #if ENABLE(OFFSCREEN_CANVAS) 2055 2054 , m_detachedOffscreenCanvases(WTFMove(detachedOffscreenCanvases)) … … 2884 2883 uint32_t index; 2885 2884 bool indexSuccessfullyRead = read(index); 2886 if (!indexSuccessfullyRead || index >= m_ imageBuffers.size()) {2885 if (!indexSuccessfullyRead || index >= m_backingStores.size()) { 2887 2886 fail(); 2888 2887 return JSValue(); … … 2890 2889 2891 2890 if (!m_imageBitmaps[index]) 2892 m_imageBitmaps[index] = ImageBitmap::create(WTFMove(m_ imageBuffers.at(index)));2891 m_imageBitmaps[index] = ImageBitmap::create(WTFMove(m_backingStores.at(index))); 2893 2892 2894 2893 auto bitmap = m_imageBitmaps[index].get(); … … 2963 2962 JSValue readImageBitmap() 2964 2963 { 2965 uint8_t originClean; 2966 uint8_t premultiplyAlpha; 2967 uint8_t forciblyPremultiplyAlpha; 2964 uint8_t serializationState; 2968 2965 int32_t logicalWidth; 2969 2966 int32_t logicalHeight; … … 2971 2968 RefPtr<ArrayBuffer> arrayBuffer; 2972 2969 2973 if (!read( originClean) || !read(premultiplyAlpha) || !read(forciblyPremultiplyAlpha) || !read(logicalWidth) || !read(logicalHeight) || !read(resolutionScale) || !readArrayBuffer(arrayBuffer)) {2970 if (!read(serializationState) || !read(logicalWidth) || !read(logicalHeight) || !read(resolutionScale) || !readArrayBuffer(arrayBuffer)) { 2974 2971 fail(); 2975 2972 return JSValue(); … … 3000 2997 buffer->putImageData(AlphaPremultiplication::Premultiplied, *imageData, { IntPoint::zero(), logicalSize }); 3001 2998 3002 auto bitmap = ImageBitmap::create( { WTFMove(buffer), ImageBuffer::SerializationState { static_cast<bool>(originClean), static_cast<bool>(premultiplyAlpha), static_cast<bool>(forciblyPremultiplyAlpha) }});2999 auto bitmap = ImageBitmap::create(ImageBitmapBacking(WTFMove(buffer), OptionSet<SerializationState>::fromRaw(serializationState))); 3003 3000 return getJSValue(bitmap); 3004 3001 } … … 3435 3432 Vector<String> m_blobFilePaths; 3436 3433 ArrayBufferContentsArray* m_sharedBuffers; 3437 Vector< std::pair<std::unique_ptr<ImageBuffer>, ImageBuffer::SerializationState>> m_imageBuffers;3434 Vector<Optional<ImageBitmapBacking>> m_backingStores; 3438 3435 Vector<RefPtr<ImageBitmap>> m_imageBitmaps; 3439 3436 #if ENABLE(OFFSCREEN_CANVAS) … … 3659 3656 } 3660 3657 3661 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>>&& imageBuffers3658 SerializedScriptValue::SerializedScriptValue(Vector<uint8_t>&& buffer, const Vector<String>& blobURLs, std::unique_ptr<ArrayBufferContentsArray> arrayBufferContentsArray, std::unique_ptr<ArrayBufferContentsArray> sharedBufferContentsArray, Vector<Optional<ImageBitmapBacking>>&& backingStores 3662 3659 #if ENABLE(OFFSCREEN_CANVAS) 3663 3660 , Vector<std::unique_ptr<DetachedOffscreenCanvas>>&& detachedOffscreenCanvases … … 3670 3667 , m_arrayBufferContentsArray(WTFMove(arrayBufferContentsArray)) 3671 3668 , m_sharedBufferContentsArray(WTFMove(sharedBufferContentsArray)) 3672 , m_ imageBuffers(WTFMove(imageBuffers))3669 , m_backingStores(WTFMove(backingStores)) 3673 3670 #if ENABLE(OFFSCREEN_CANVAS) 3674 3671 , m_detachedOffscreenCanvases(WTFMove(detachedOffscreenCanvases)) … … 3700 3697 } 3701 3698 3702 for (auto& pair : m_imageBuffers) {3703 if ( pair.first)3704 cost += pair.first->memoryCost();3699 for (auto& backingStore : m_backingStores) { 3700 if (auto buffer = backingStore ? backingStore->buffer() : nullptr) 3701 cost += buffer->memoryCost(); 3705 3702 } 3706 3703 … … 3926 3923 return arrayBufferContentsArray.releaseException(); 3927 3924 3928 auto imageBuffers = ImageBitmap::detachBitmaps(WTFMove(imageBitmaps));3925 auto backingStores = ImageBitmap::detachBitmaps(WTFMove(imageBitmaps)); 3929 3926 3930 3927 #if ENABLE(OFFSCREEN_CANVAS) … … 3934 3931 #endif 3935 3932 3936 return adoptRef(*new SerializedScriptValue(WTFMove(buffer), blobURLs, arrayBufferContentsArray.releaseReturnValue(), context == SerializationContext::WorkerPostMessage ? WTFMove(sharedBuffers) : nullptr, WTFMove( imageBuffers)3933 return adoptRef(*new SerializedScriptValue(WTFMove(buffer), blobURLs, arrayBufferContentsArray.releaseReturnValue(), context == SerializationContext::WorkerPostMessage ? WTFMove(sharedBuffers) : nullptr, WTFMove(backingStores) 3937 3934 #if ENABLE(OFFSCREEN_CANVAS) 3938 3935 , WTFMove(detachedCanvases) … … 3990 3987 JSValue SerializedScriptValue::deserialize(JSGlobalObject& lexicalGlobalObject, JSGlobalObject* globalObject, const Vector<RefPtr<MessagePort>>& messagePorts, const Vector<String>& blobURLs, const Vector<String>& blobFilePaths, SerializationErrorMode throwExceptions) 3991 3988 { 3992 DeserializationResult result = CloneDeserializer::deserialize(&lexicalGlobalObject, globalObject, messagePorts, WTFMove(m_ imageBuffers)3989 DeserializationResult result = CloneDeserializer::deserialize(&lexicalGlobalObject, globalObject, messagePorts, WTFMove(m_backingStores) 3993 3990 #if ENABLE(OFFSCREEN_CANVAS) 3994 3991 , WTFMove(m_detachedOffscreenCanvases) -
trunk/Source/WebCore/bindings/js/SerializedScriptValue.h
r265208 r267615 28 28 29 29 #include "ExceptionOr.h" 30 #include "ImageBuffer.h"31 30 #include <JavaScriptCore/ArrayBuffer.h> 32 31 #include <JavaScriptCore/JSCJSValue.h> … … 52 51 #endif 53 52 class IDBValue; 54 class ImageBitmap;55 53 class MessagePort; 54 class ImageBitmapBacking; 56 55 class SharedBuffer; 57 56 enum class SerializationReturnCode; … … 118 117 WEBCORE_EXPORT SerializedScriptValue(Vector<unsigned char>&&); 119 118 WEBCORE_EXPORT SerializedScriptValue(Vector<unsigned char>&&, std::unique_ptr<ArrayBufferContentsArray>); 120 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>>&& imageBuffers119 SerializedScriptValue(Vector<unsigned char>&&, const Vector<String>& blobURLs, std::unique_ptr<ArrayBufferContentsArray>, std::unique_ptr<ArrayBufferContentsArray> sharedBuffers, Vector<Optional<ImageBitmapBacking>>&& backingStores 121 120 #if ENABLE(OFFSCREEN_CANVAS) 122 121 , Vector<std::unique_ptr<DetachedOffscreenCanvas>>&& = { } … … 132 131 std::unique_ptr<ArrayBufferContentsArray> m_arrayBufferContentsArray; 133 132 std::unique_ptr<ArrayBufferContentsArray> m_sharedBufferContentsArray; 134 Vector< std::pair<std::unique_ptr<ImageBuffer>, ImageBuffer::SerializationState>> m_imageBuffers;133 Vector<Optional<ImageBitmapBacking>> m_backingStores; 135 134 #if ENABLE(OFFSCREEN_CANVAS) 136 135 Vector<std::unique_ptr<DetachedOffscreenCanvas>> m_detachedOffscreenCanvases; -
trunk/Source/WebCore/html/ImageBitmap.cpp
r265360 r267615 70 70 Ref<ImageBitmap> ImageBitmap::create(IntSize size) 71 71 { 72 return create(ImageBuffer::create(FloatSize(size.width(), size.height()), bufferRenderingMode)); 73 } 74 75 Ref<ImageBitmap> ImageBitmap::create(std::pair<std::unique_ptr<ImageBuffer>, ImageBuffer::SerializationState>&& buffer) 76 { 77 auto imageBitmap = create(WTFMove(buffer.first)); 78 imageBitmap->m_originClean = buffer.second.originClean; 79 imageBitmap->m_premultiplyAlpha = buffer.second.premultiplyAlpha; 80 imageBitmap->m_forciblyPremultiplyAlpha = buffer.second.forciblyPremultiplyAlpha; 81 return imageBitmap; 82 } 83 84 Ref<ImageBitmap> ImageBitmap::create(std::unique_ptr<ImageBuffer>&& buffer) 85 { 86 return adoptRef(*new ImageBitmap(WTFMove(buffer))); 72 return create({ ImageBuffer::create(FloatSize(size.width(), size.height()), bufferRenderingMode) }); 73 } 74 75 Ref<ImageBitmap> ImageBitmap::create(Optional<ImageBitmapBacking>&& backingStore) 76 { 77 return adoptRef(*new ImageBitmap(WTFMove(backingStore))); 87 78 } 88 79 … … 96 87 } 97 88 98 Vector< std::pair<std::unique_ptr<ImageBuffer>, ImageBuffer::SerializationState>> ImageBitmap::detachBitmaps(Vector<RefPtr<ImageBitmap>>&& bitmaps)99 { 100 Vector< std::pair<std::unique_ptr<ImageBuffer>, ImageBuffer::SerializationState>> buffers;89 Vector<Optional<ImageBitmapBacking>> ImageBitmap::detachBitmaps(Vector<RefPtr<ImageBitmap>>&& bitmaps) 90 { 91 Vector<Optional<ImageBitmapBacking>> buffers; 101 92 for (auto& bitmap : bitmaps) 102 buffers.append( std::make_pair(bitmap->transferOwnershipAndClose(), ImageBuffer::SerializationState { bitmap->originClean(), bitmap->premultiplyAlpha(), bitmap->forciblyPremultiplyAlpha() }));93 buffers.append(bitmap->takeImageBitmapBacking()); 103 94 return buffers; 104 95 } 105 106 96 107 97 void ImageBitmap::createPromise(ScriptExecutionContext& scriptExecutionContext, ImageBitmap::Source&& source, ImageBitmapOptions&& options, int sx, int sy, int sw, int sh, ImageBitmap::Promise&& promise) … … 244 234 auto bitmapData = ImageBuffer::create(FloatSize(1, 1), bufferRenderingMode); 245 235 246 // 7. Create a new ImageBitmap object.247 auto imageBitmap = create(WTFMove(bitmapData));248 249 236 // 9. If the origin of image's image is not the same origin as the origin specified by the 250 237 // entry settings object, then set the origin-clean flag of the ImageBitmap object's 251 238 // bitmap to false. 252 imageBitmap->m_originClean = originClean; 239 OptionSet<SerializationState> serializationState; 240 if (originClean) 241 serializationState.add(SerializationState::OriginClean); 242 243 // 7. Create a new ImageBitmap object. 244 auto imageBitmap = create(ImageBitmapBacking(WTFMove(bitmapData), serializationState)); 253 245 254 246 // 10. Return a new promise, but continue running these steps in parallel. … … 374 366 bitmapData->context().drawImage(*imageForRender, destRect, sourceRectangle.releaseReturnValue(), { interpolationQualityForResizeQuality(options.resizeQuality), imageOrientationForOrientation(options.imageOrientation) }); 375 367 376 // 7. Create a new ImageBitmap object.377 auto imageBitmap = create(WTFMove(bitmapData));378 379 368 // 9. If the origin of image's image is not the same origin as the origin specified by the 380 369 // entry settings object, then set the origin-clean flag of the ImageBitmap object's 381 370 // bitmap to false. 382 383 imageBitmap->m_originClean = !taintsOrigin(*cachedImage); 384 385 imageBitmap->m_premultiplyAlpha = (alphaPremultiplicationForPremultiplyAlpha(options.premultiplyAlpha) == AlphaPremultiplication::Premultiplied); 371 OptionSet<SerializationState> serializationState; 372 if (!taintsOrigin(*cachedImage)) 373 serializationState.add(SerializationState::OriginClean); 374 375 if (alphaPremultiplicationForPremultiplyAlpha(options.premultiplyAlpha) == AlphaPremultiplication::Premultiplied) 376 serializationState.add(SerializationState::PremultiplyAlpha); 377 378 // 7. Create a new ImageBitmap object. 379 auto imageBitmap = create(ImageBitmapBacking(WTFMove(bitmapData), serializationState)); 386 380 387 381 // 10. Return a new promise, but continue running these steps in parallel. … … 440 434 bitmapData->context().drawImage(*imageForRender, destRect, sourceRectangle.releaseReturnValue(), { interpolationQualityForResizeQuality(options.resizeQuality), imageOrientationForOrientation(options.imageOrientation) }); 441 435 442 // 3. Create a new ImageBitmap object.443 auto imageBitmap = create(WTFMove(bitmapData));444 445 436 // 5. Set the origin-clean flag of the ImageBitmap object's bitmap to the same value as 446 437 // the origin-clean flag of the canvas element's bitmap. 447 448 imageBitmap->m_originClean = canvas.originClean(); 449 450 imageBitmap->m_premultiplyAlpha = (alphaPremultiplicationForPremultiplyAlpha(options.premultiplyAlpha) == AlphaPremultiplication::Premultiplied); 438 OptionSet<SerializationState> serializationState; 439 if (canvas.originClean()) 440 serializationState.add(SerializationState::OriginClean); 441 442 if (alphaPremultiplicationForPremultiplyAlpha(options.premultiplyAlpha) == AlphaPremultiplication::Premultiplied) 443 serializationState.add(SerializationState::PremultiplyAlpha); 444 445 // 3. Create a new ImageBitmap object. 446 auto imageBitmap = create(ImageBitmapBacking(WTFMove(bitmapData), serializationState)); 451 447 452 448 // 6. Return a new promise, but continue running these steps in parallel. … … 515 511 } 516 512 517 // 5. Let imageBitmap be a new ImageBitmap object.518 auto imageBitmap = create(WTFMove(bitmapData));519 520 513 // 6.3. If the origin of image's video is not same origin with entry 521 514 // settings object's origin, then set the origin-clean flag of 522 515 // image's bitmap to false. 523 imageBitmap->m_originClean = !taintsOrigin(scriptExecutionContext.securityOrigin(), *video); 524 525 imageBitmap->m_premultiplyAlpha = (alphaPremultiplicationForPremultiplyAlpha(options.premultiplyAlpha) == AlphaPremultiplication::Premultiplied); 516 OptionSet<SerializationState> serializationState; 517 if (!taintsOrigin(scriptExecutionContext.securityOrigin(), *video)) 518 serializationState.add(SerializationState::OriginClean); 519 520 if (alphaPremultiplicationForPremultiplyAlpha(options.premultiplyAlpha) == AlphaPremultiplication::Premultiplied) 521 serializationState.add(SerializationState::PremultiplyAlpha); 522 523 // 5. Let imageBitmap be a new ImageBitmap object. 524 auto imageBitmap = create(ImageBitmapBacking(WTFMove(bitmapData), serializationState)); 526 525 527 526 // 6.4.1. Resolve p with imageBitmap. … … 567 566 bitmapData->context().drawImage(*imageForRender, destRect, sourceRectangle.releaseReturnValue(), { interpolationQualityForResizeQuality(options.resizeQuality), imageOrientationForOrientation(options.imageOrientation) }); 568 567 569 // 3. Create a new ImageBitmap object.570 auto imageBitmap = create(WTFMove(bitmapData));571 572 568 // 5. Set the origin-clean flag of the ImageBitmap object's bitmap to the same 573 569 // value as the origin-clean flag of the bitmap of the image argument. 574 imageBitmap->m_originClean = existingImageBitmap->originClean(); 575 576 imageBitmap->m_premultiplyAlpha = (alphaPremultiplicationForPremultiplyAlpha(options.premultiplyAlpha) == AlphaPremultiplication::Premultiplied); 577 578 // At least in the Core Graphics backend, when creating an ImageBitmap from 579 // an ImageBitmap, the alpha channel of bitmapData isn't premultiplied even 580 // though the alpha mode of the internal surface claims it is. Instruct 581 // users of this ImageBitmap to ignore the internal surface's alpha mode. 582 imageBitmap->m_forciblyPremultiplyAlpha = imageBitmap->m_premultiplyAlpha; 570 OptionSet<SerializationState> serializationState; 571 if (existingImageBitmap->originClean()) 572 serializationState.add(SerializationState::OriginClean); 573 574 if (alphaPremultiplicationForPremultiplyAlpha(options.premultiplyAlpha) == AlphaPremultiplication::Premultiplied) { 575 serializationState.add(SerializationState::PremultiplyAlpha); 576 577 // At least in the Core Graphics backend, when creating an ImageBitmap from 578 // an ImageBitmap, the alpha channel of bitmapData isn't premultiplied even 579 // though the alpha mode of the internal surface claims it is. Instruct 580 // users of this ImageBitmap to ignore the internal surface's alpha mode. 581 serializationState.add(SerializationState::ForciblyPremultiplyAlpha); 582 } 583 584 // 3. Create a new ImageBitmap object. 585 auto imageBitmap = create(ImageBitmapBacking(WTFMove(bitmapData), serializationState)); 583 586 584 587 // 6. Return a new promise, but continue running these steps in parallel. … … 753 756 bitmapData->context().drawImage(*image, destRect, sourceRectangle.releaseReturnValue(), { interpolationQualityForResizeQuality(options.resizeQuality), imageOrientationForOrientation(options.imageOrientation) }); 754 757 755 auto imageBitmap = create(WTFMove(bitmapData)); 756 757 imageBitmap->m_premultiplyAlpha = (alphaPremultiplicationForPremultiplyAlpha(options.premultiplyAlpha) == AlphaPremultiplication::Premultiplied); 758 OptionSet<SerializationState> serializationState = SerializationState::OriginClean; 759 if (alphaPremultiplicationForPremultiplyAlpha(options.premultiplyAlpha) == AlphaPremultiplication::Premultiplied) 760 serializationState.add(SerializationState::PremultiplyAlpha); 761 762 auto imageBitmap = create(ImageBitmapBacking(WTFMove(bitmapData), serializationState)); 758 763 759 764 promise.resolve(WTFMove(imageBitmap)); … … 800 805 && options.imageOrientation == ImageBitmapOptions::Orientation::None) { 801 806 bitmapData->putImageData(AlphaPremultiplication::Unpremultiplied, *imageData, sourceRectangle.releaseReturnValue(), { }, alphaPremultiplication); 802 auto imageBitmap = create( WTFMove(bitmapData));807 auto imageBitmap = create(ImageBitmapBacking(WTFMove(bitmapData))); 803 808 // The result is implicitly origin-clean, and alpha premultiplication has already been handled. 804 809 promise.resolve(WTFMove(imageBitmap)); … … 814 819 815 820 // 6.4.1. Resolve p with ImageBitmap. 816 auto imageBitmap = create( WTFMove(bitmapData));821 auto imageBitmap = create({ WTFMove(bitmapData) }); 817 822 // The result is implicitly origin-clean, and alpha premultiplication has already been handled. 818 823 promise.resolve(WTFMove(imageBitmap)); 819 824 } 820 825 821 ImageBitmap::ImageBitmap( std::unique_ptr<ImageBuffer>&& buffer)822 : m_b itmapData(WTFMove(buffer))823 { 824 ASSERT (m_bitmapData);826 ImageBitmap::ImageBitmap(Optional<ImageBitmapBacking>&& backingStore) 827 : m_backingStore(WTFMove(backingStore)) 828 { 829 ASSERT_IMPLIES(m_backingStore, m_backingStore->buffer()); 825 830 } 826 831 827 832 ImageBitmap::~ImageBitmap() = default; 828 833 829 unsigned ImageBitmap::width() const 830 { 831 if (m_detached || !m_bitmapData) 832 return 0; 833 834 // FIXME: Is this the right width? 835 return m_bitmapData->logicalSize().width(); 836 } 837 838 unsigned ImageBitmap::height() const 839 { 840 if (m_detached || !m_bitmapData) 841 return 0; 842 843 // FIXME: Is this the right height? 844 return m_bitmapData->logicalSize().height(); 845 } 846 847 void ImageBitmap::close() 848 { 849 m_detached = true; 850 m_bitmapData = nullptr; 851 } 852 853 std::unique_ptr<ImageBuffer> ImageBitmap::transferOwnershipAndClose() 854 { 855 m_detached = true; 856 return WTFMove(m_bitmapData); 857 } 858 859 } 834 Optional<ImageBitmapBacking> ImageBitmap::takeImageBitmapBacking() 835 { 836 return std::exchange(m_backingStore, WTF::nullopt); 837 } 838 839 std::unique_ptr<ImageBuffer> ImageBitmap::takeImageBuffer() 840 { 841 if (auto backingStore = takeImageBitmapBacking()) 842 return backingStore->takeImageBuffer(); 843 ASSERT(isDetached()); 844 return nullptr; 845 } 846 847 } // namespace WebCore -
trunk/Source/WebCore/html/ImageBitmap.h
r265360 r267615 27 27 28 28 #include "IDLTypes.h" 29 #include "ImageB uffer.h"29 #include "ImageBitmapBacking.h" 30 30 #include "ScriptWrappable.h" 31 31 #include <wtf/RefCounted.h> … … 84 84 85 85 static Ref<ImageBitmap> create(IntSize); 86 static Ref<ImageBitmap> create( std::pair<std::unique_ptr<ImageBuffer>, ImageBuffer::SerializationState>&&);86 static Ref<ImageBitmap> create(Optional<ImageBitmapBacking>&&); 87 87 88 88 ~ImageBitmap(); 89 89 90 unsigned width() const; 91 unsigned height() const; 92 void close(); 90 ImageBuffer* buffer() const { return m_backingStore ? m_backingStore->buffer() : nullptr; } 91 // This function has the implicit side-effect of detaching the backing store. 92 // It returns nullptr if the ImageBitmap's already detached. 93 std::unique_ptr<ImageBuffer> takeImageBuffer(); 94 OptionSet<SerializationState> serializationState() const { return m_backingStore ? m_backingStore->serializationState() : SerializationState(); } 93 95 94 bool isDetached() const { return m_detached; } 96 unsigned width() const { return m_backingStore ? m_backingStore->width() : 0; } 97 unsigned height() const { return m_backingStore ? m_backingStore->height() : 0; } 95 98 96 ImageBuffer* buffer() { return m_bitmapData.get(); } 99 bool originClean() const { return m_backingStore && m_backingStore->originClean(); } 100 bool premultiplyAlpha() const { return m_backingStore && m_backingStore->premultiplyAlpha(); } 101 bool forciblyPremultiplyAlpha() const { return m_backingStore && m_backingStore->forciblyPremultiplyAlpha(); } 97 102 98 bool originClean() const { return m_originClean; } 103 Optional<ImageBitmapBacking> takeImageBitmapBacking(); 104 bool isDetached() const { return !m_backingStore.hasValue(); } 105 void close() { takeImageBitmapBacking(); } 99 106 100 bool premultiplyAlpha() const { return m_premultiplyAlpha; } 101 102 // When WebGL consumes an Image coming from an ImageBitmap's ImageBuffer, it typically honors 103 // the alpha mode of that native image - CGImageAlphaInfo in the Core Graphics backend. For 104 // ImageBitmaps created from ImageBitmaps, this information is not accurate, and callers must be 105 // told to ignore the alpha mode, and forcibly premultiply the alpha channel. 106 bool forciblyPremultiplyAlpha() const { return m_forciblyPremultiplyAlpha; } 107 108 std::unique_ptr<ImageBuffer> transferOwnershipAndClose(); 109 110 static Vector<std::pair<std::unique_ptr<ImageBuffer>, ImageBuffer::SerializationState>> detachBitmaps(Vector<RefPtr<ImageBitmap>>&&); 107 static Vector<Optional<ImageBitmapBacking>> detachBitmaps(Vector<RefPtr<ImageBitmap>>&&); 111 108 112 109 private: … … 114 111 friend class PendingImageBitmap; 115 112 116 static Ref<ImageBitmap> create(std::unique_ptr<ImageBuffer>&&); 117 ImageBitmap(std::unique_ptr<ImageBuffer>&&); 113 ImageBitmap(Optional<ImageBitmapBacking>&&); 118 114 119 115 static void resolveWithBlankImageBuffer(bool originClean, Promise&&); … … 134 130 static void createFromBuffer(Ref<ArrayBuffer>&&, String mimeType, long long expectedContentLength, const URL&, ImageBitmapOptions&&, Optional<IntRect>, Promise&&); 135 131 136 std::unique_ptr<ImageBuffer> m_bitmapData; 137 bool m_detached { false }; 138 bool m_originClean { true }; 139 bool m_premultiplyAlpha { false }; 140 bool m_forciblyPremultiplyAlpha { false }; 132 Optional<ImageBitmapBacking> m_backingStore; 141 133 }; 142 134 -
trunk/Source/WebCore/html/OffscreenCanvas.cpp
r266275 r267615 251 251 252 252 if (!m_hasCreatedImageBuffer) 253 return { ImageBitmap::create( { ImageBuffer::create(size(), RenderingMode::Unaccelerated), ImageBuffer::SerializationState { true, false, false }}) };253 return { ImageBitmap::create(ImageBitmapBacking(ImageBuffer::create(size(), RenderingMode::Unaccelerated))) }; 254 254 255 255 auto buffer = takeImageBuffer(); … … 257 257 return { RefPtr<ImageBitmap> { nullptr } }; 258 258 259 return { ImageBitmap::create( { WTFMove(buffer), ImageBuffer::SerializationState { originClean(), false, false }}) };259 return { ImageBitmap::create(ImageBitmapBacking(WTFMove(buffer), originClean() ? SerializationState::OriginClean : SerializationState())) }; 260 260 } 261 261 -
trunk/Source/WebCore/html/canvas/ImageBitmapRenderingContext.cpp
r254893 r267615 118 118 else 119 119 canvas()->setOriginTainted(); 120 canvas()->setImageBufferAndMarkDirty(imageBitmap->t ransferOwnershipAndClose());120 canvas()->setImageBufferAndMarkDirty(imageBitmap->takeImageBuffer()); 121 121 } 122 122 -
trunk/Source/WebCore/platform/graphics/ImageBuffer.h
r265360 r267615 39 39 class ImageBuffer { 40 40 public: 41 struct SerializationState {42 bool originClean { false };43 bool premultiplyAlpha { false };44 bool forciblyPremultiplyAlpha { false };45 };46 47 41 // Will return a null pointer on allocation failure. 48 42 WEBCORE_EXPORT static std::unique_ptr<ImageBuffer> create(const FloatSize&, ShouldAccelerate, ShouldUseDisplayList, RenderingPurpose, float resolutionScale = 1, ColorSpace = ColorSpace::SRGB, const HostWindow* = nullptr);
Note:
See TracChangeset
for help on using the changeset viewer.