diff options
author | xidachen <xidachen@chromium.org> | 2016-01-15 18:16:33 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-01-16 02:18:08 +0000 |
commit | 6823042bfec8be3ce42407aafb455fc5c35f6206 (patch) | |
tree | 7288769be0ed6905c275c1aaae0c123032f206c4 | |
parent | e88912d4be5f46564412daff14dcf125dbcf37a8 (diff) | |
download | chromium_src-6823042bfec8be3ce42407aafb455fc5c35f6206.zip chromium_src-6823042bfec8be3ce42407aafb455fc5c35f6206.tar.gz chromium_src-6823042bfec8be3ce42407aafb455fc5c35f6206.tar.bz2 |
Start a basic framework for ImageBitmap options
This CL starts a basic framework for implementing ImageBitmap options.
All it does is add a createImageBitmap() in the idl file that takes a
dictionary which contains the ImageBitmap options. Since we will be
shipping ImageBitmap soon, this method is made to hide behind the experimental
flag. From there, almost all the ImageBitmap constructors are changed
to reflect that.
Note that this change should not change the current behavior of ImageBitmap
and createImageBitmap, because these ImageBitmap options are set to be the
current default value.
BUG=249382
Review URL: https://codereview.chromium.org/1588713002
Cr-Commit-Position: refs/heads/master@{#369924}
17 files changed, 104 insertions, 60 deletions
diff --git a/third_party/WebKit/Source/core/core.gypi b/third_party/WebKit/Source/core/core.gypi index 4909759..52a0477 100644 --- a/third_party/WebKit/Source/core/core.gypi +++ b/third_party/WebKit/Source/core/core.gypi @@ -3645,6 +3645,7 @@ 'html/MediaKeyEventInit.idl', 'html/canvas/CanvasContextCreationAttributes.idl', 'html/track/TrackEventInit.idl', + 'imagebitmap/ImageBitmapOptions.idl', 'input/InputDeviceCapabilitiesInit.idl', 'page/EventSourceInit.idl', 'timing/PerformanceObserverInit.idl', @@ -3742,6 +3743,8 @@ '<(blink_core_output_dir)/html/canvas/CanvasContextCreationAttributes.h', '<(blink_core_output_dir)/html/track/TrackEventInit.cpp', '<(blink_core_output_dir)/html/track/TrackEventInit.h', + '<(blink_core_output_dir)/imagebitmap/ImageBitmapOptions.cpp', + '<(blink_core_output_dir)/imagebitmap/ImageBitmapOptions.h', '<(blink_core_output_dir)/input/InputDeviceCapabilitiesInit.cpp', '<(blink_core_output_dir)/input/InputDeviceCapabilitiesInit.h', '<(blink_core_output_dir)/page/EventSourceInit.cpp', diff --git a/third_party/WebKit/Source/core/frame/ImageBitmap.cpp b/third_party/WebKit/Source/core/frame/ImageBitmap.cpp index 8b15261..7f848ba 100644 --- a/third_party/WebKit/Source/core/frame/ImageBitmap.cpp +++ b/third_party/WebKit/Source/core/frame/ImageBitmap.cpp @@ -45,13 +45,13 @@ static PassRefPtr<StaticBitmapImage> cropImage(Image* image, const IntRect& crop return StaticBitmapImage::create(adoptRef(surface->newImageSnapshot())); } -ImageBitmap::ImageBitmap(HTMLImageElement* image, const IntRect& cropRect, Document* document) +ImageBitmap::ImageBitmap(HTMLImageElement* image, const IntRect& cropRect, Document* document, const ImageBitmapOptions& options) { m_image = cropImage(image->cachedImage()->image(), cropRect); m_image->setOriginClean(!image->wouldTaintOrigin(document->securityOrigin())); } -ImageBitmap::ImageBitmap(HTMLVideoElement* video, const IntRect& cropRect, Document* document) +ImageBitmap::ImageBitmap(HTMLVideoElement* video, const IntRect& cropRect, Document* document, const ImageBitmapOptions& options) { IntSize playerSize; if (video->webMediaPlayer()) @@ -69,14 +69,14 @@ ImageBitmap::ImageBitmap(HTMLVideoElement* video, const IntRect& cropRect, Docum m_image->setOriginClean(!video->wouldTaintOrigin(document->securityOrigin())); } -ImageBitmap::ImageBitmap(HTMLCanvasElement* canvas, const IntRect& cropRect) +ImageBitmap::ImageBitmap(HTMLCanvasElement* canvas, const IntRect& cropRect, const ImageBitmapOptions& options) { ASSERT(canvas->isPaintable()); m_image = cropImage(canvas->copiedImage(BackBuffer, PreferAcceleration).get(), cropRect); m_image->setOriginClean(canvas->originClean()); } -ImageBitmap::ImageBitmap(ImageData* data, const IntRect& cropRect) +ImageBitmap::ImageBitmap(ImageData* data, const IntRect& cropRect, const ImageBitmapOptions& options) { IntRect srcRect = intersection(cropRect, IntRect(IntPoint(), data->size())); @@ -98,13 +98,13 @@ ImageBitmap::ImageBitmap(ImageData* data, const IntRect& cropRect) m_image = StaticBitmapImage::create(buffer->newSkImageSnapshot(PreferNoAcceleration)); } -ImageBitmap::ImageBitmap(ImageBitmap* bitmap, const IntRect& cropRect) +ImageBitmap::ImageBitmap(ImageBitmap* bitmap, const IntRect& cropRect, const ImageBitmapOptions& options) { m_image = cropImage(bitmap->bitmapImage(), cropRect); m_image->setOriginClean(bitmap->originClean()); } -ImageBitmap::ImageBitmap(PassRefPtr<StaticBitmapImage> image, const IntRect& cropRect) +ImageBitmap::ImageBitmap(PassRefPtr<StaticBitmapImage> image, const IntRect& cropRect, const ImageBitmapOptions& options) { m_image = cropImage(image.get(), cropRect); m_image->setOriginClean(image->originClean()); @@ -126,40 +126,40 @@ ImageBitmap::~ImageBitmap() { } -PassRefPtrWillBeRawPtr<ImageBitmap> ImageBitmap::create(HTMLImageElement* image, const IntRect& cropRect, Document* document) +PassRefPtrWillBeRawPtr<ImageBitmap> ImageBitmap::create(HTMLImageElement* image, const IntRect& cropRect, Document* document, const ImageBitmapOptions& options) { IntRect normalizedCropRect = normalizeRect(cropRect); - return adoptRefWillBeNoop(new ImageBitmap(image, normalizedCropRect, document)); + return adoptRefWillBeNoop(new ImageBitmap(image, normalizedCropRect, document, options)); } -PassRefPtrWillBeRawPtr<ImageBitmap> ImageBitmap::create(HTMLVideoElement* video, const IntRect& cropRect, Document* document) +PassRefPtrWillBeRawPtr<ImageBitmap> ImageBitmap::create(HTMLVideoElement* video, const IntRect& cropRect, Document* document, const ImageBitmapOptions& options) { IntRect normalizedCropRect = normalizeRect(cropRect); - return adoptRefWillBeNoop(new ImageBitmap(video, normalizedCropRect, document)); + return adoptRefWillBeNoop(new ImageBitmap(video, normalizedCropRect, document, options)); } -PassRefPtrWillBeRawPtr<ImageBitmap> ImageBitmap::create(HTMLCanvasElement* canvas, const IntRect& cropRect) +PassRefPtrWillBeRawPtr<ImageBitmap> ImageBitmap::create(HTMLCanvasElement* canvas, const IntRect& cropRect, const ImageBitmapOptions& options) { IntRect normalizedCropRect = normalizeRect(cropRect); - return adoptRefWillBeNoop(new ImageBitmap(canvas, normalizedCropRect)); + return adoptRefWillBeNoop(new ImageBitmap(canvas, normalizedCropRect, options)); } -PassRefPtrWillBeRawPtr<ImageBitmap> ImageBitmap::create(ImageData* data, const IntRect& cropRect) +PassRefPtrWillBeRawPtr<ImageBitmap> ImageBitmap::create(ImageData* data, const IntRect& cropRect, const ImageBitmapOptions& options) { IntRect normalizedCropRect = normalizeRect(cropRect); - return adoptRefWillBeNoop(new ImageBitmap(data, normalizedCropRect)); + return adoptRefWillBeNoop(new ImageBitmap(data, normalizedCropRect, options)); } -PassRefPtrWillBeRawPtr<ImageBitmap> ImageBitmap::create(ImageBitmap* bitmap, const IntRect& cropRect) +PassRefPtrWillBeRawPtr<ImageBitmap> ImageBitmap::create(ImageBitmap* bitmap, const IntRect& cropRect, const ImageBitmapOptions& options) { IntRect normalizedCropRect = normalizeRect(cropRect); - return adoptRefWillBeNoop(new ImageBitmap(bitmap, normalizedCropRect)); + return adoptRefWillBeNoop(new ImageBitmap(bitmap, normalizedCropRect, options)); } -PassRefPtrWillBeRawPtr<ImageBitmap> ImageBitmap::create(PassRefPtr<StaticBitmapImage> image, const IntRect& cropRect) +PassRefPtrWillBeRawPtr<ImageBitmap> ImageBitmap::create(PassRefPtr<StaticBitmapImage> image, const IntRect& cropRect, const ImageBitmapOptions& options) { IntRect normalizedCropRect = normalizeRect(cropRect); - return adoptRefWillBeNoop(new ImageBitmap(image, normalizedCropRect)); + return adoptRefWillBeNoop(new ImageBitmap(image, normalizedCropRect, options)); } PassRefPtrWillBeRawPtr<ImageBitmap> ImageBitmap::create(PassRefPtr<StaticBitmapImage> image) @@ -191,13 +191,13 @@ IntSize ImageBitmap::size() const return IntSize(m_image->width(), m_image->height()); } -ScriptPromise ImageBitmap::createImageBitmap(ScriptState* scriptState, EventTarget& eventTarget, int sx, int sy, int sw, int sh, ExceptionState& exceptionState) +ScriptPromise ImageBitmap::createImageBitmap(ScriptState* scriptState, EventTarget& eventTarget, int sx, int sy, int sw, int sh, const ImageBitmapOptions& options, ExceptionState& exceptionState) { if (!sw || !sh) { exceptionState.throwDOMException(IndexSizeError, String::format("The source %s provided is 0.", sw ? "height" : "width")); return ScriptPromise(); } - return ImageBitmapSource::fulfillImageBitmap(scriptState, create(this, IntRect(sx, sy, sw, sh))); + return ImageBitmapSource::fulfillImageBitmap(scriptState, create(this, IntRect(sx, sy, sw, sh), options)); } void ImageBitmap::notifyImageSourceChanged() diff --git a/third_party/WebKit/Source/core/frame/ImageBitmap.h b/third_party/WebKit/Source/core/frame/ImageBitmap.h index 6af36c0..5d272ca 100644 --- a/third_party/WebKit/Source/core/frame/ImageBitmap.h +++ b/third_party/WebKit/Source/core/frame/ImageBitmap.h @@ -9,6 +9,7 @@ #include "core/CoreExport.h" #include "core/html/HTMLImageElement.h" #include "core/html/canvas/CanvasImageSource.h" +#include "core/imagebitmap/ImageBitmapOptions.h" #include "core/imagebitmap/ImageBitmapSource.h" #include "platform/geometry/IntRect.h" #include "platform/graphics/Image.h" @@ -28,13 +29,13 @@ class CORE_EXPORT ImageBitmap final : public RefCountedWillBeGarbageCollectedFin DEFINE_WRAPPERTYPEINFO(); WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(ImageBitmap); public: - static PassRefPtrWillBeRawPtr<ImageBitmap> create(HTMLImageElement*, const IntRect&, Document*); - static PassRefPtrWillBeRawPtr<ImageBitmap> create(HTMLVideoElement*, const IntRect&, Document*); - static PassRefPtrWillBeRawPtr<ImageBitmap> create(HTMLCanvasElement*, const IntRect&); - static PassRefPtrWillBeRawPtr<ImageBitmap> create(ImageData*, const IntRect&); - static PassRefPtrWillBeRawPtr<ImageBitmap> create(ImageBitmap*, const IntRect&); + static PassRefPtrWillBeRawPtr<ImageBitmap> create(HTMLImageElement*, const IntRect&, Document*, const ImageBitmapOptions& = ImageBitmapOptions()); + static PassRefPtrWillBeRawPtr<ImageBitmap> create(HTMLVideoElement*, const IntRect&, Document*, const ImageBitmapOptions& = ImageBitmapOptions()); + static PassRefPtrWillBeRawPtr<ImageBitmap> create(HTMLCanvasElement*, const IntRect&, const ImageBitmapOptions& = ImageBitmapOptions()); + static PassRefPtrWillBeRawPtr<ImageBitmap> create(ImageData*, const IntRect&, const ImageBitmapOptions& = ImageBitmapOptions()); + static PassRefPtrWillBeRawPtr<ImageBitmap> create(ImageBitmap*, const IntRect&, const ImageBitmapOptions& = ImageBitmapOptions()); static PassRefPtrWillBeRawPtr<ImageBitmap> create(PassRefPtr<StaticBitmapImage>); - static PassRefPtrWillBeRawPtr<ImageBitmap> create(PassRefPtr<StaticBitmapImage>, const IntRect&); + static PassRefPtrWillBeRawPtr<ImageBitmap> create(PassRefPtr<StaticBitmapImage>, const IntRect&, const ImageBitmapOptions& = ImageBitmapOptions()); StaticBitmapImage* bitmapImage() const { return (m_image) ? m_image.get() : nullptr; } unsigned long width() const; @@ -55,18 +56,18 @@ public: // ImageBitmapSource implementation IntSize bitmapSourceSize() const override { return size(); } - ScriptPromise createImageBitmap(ScriptState*, EventTarget&, int sx, int sy, int sw, int sh, ExceptionState&) override; + ScriptPromise createImageBitmap(ScriptState*, EventTarget&, int sx, int sy, int sw, int sh, const ImageBitmapOptions&, ExceptionState&) override; DECLARE_VIRTUAL_TRACE(); private: - ImageBitmap(HTMLImageElement*, const IntRect&, Document*); - ImageBitmap(HTMLVideoElement*, const IntRect&, Document*); - ImageBitmap(HTMLCanvasElement*, const IntRect&); - ImageBitmap(ImageData*, const IntRect&); - ImageBitmap(ImageBitmap*, const IntRect&); + ImageBitmap(HTMLImageElement*, const IntRect&, Document*, const ImageBitmapOptions&); + ImageBitmap(HTMLVideoElement*, const IntRect&, Document*, const ImageBitmapOptions&); + ImageBitmap(HTMLCanvasElement*, const IntRect&, const ImageBitmapOptions&); + ImageBitmap(ImageData*, const IntRect&, const ImageBitmapOptions&); + ImageBitmap(ImageBitmap*, const IntRect&, const ImageBitmapOptions&); ImageBitmap(PassRefPtr<StaticBitmapImage>); - ImageBitmap(PassRefPtr<StaticBitmapImage>, const IntRect&); + ImageBitmap(PassRefPtr<StaticBitmapImage>, const IntRect&, const ImageBitmapOptions&); // ImageLoaderClient void notifyImageSourceChanged() override; diff --git a/third_party/WebKit/Source/core/html/HTMLCanvasElement.cpp b/third_party/WebKit/Source/core/html/HTMLCanvasElement.cpp index 07a62ea..7d05c51 100644 --- a/third_party/WebKit/Source/core/html/HTMLCanvasElement.cpp +++ b/third_party/WebKit/Source/core/html/HTMLCanvasElement.cpp @@ -43,6 +43,7 @@ #include "core/html/canvas/CanvasFontCache.h" #include "core/html/canvas/CanvasRenderingContext.h" #include "core/html/canvas/CanvasRenderingContextFactory.h" +#include "core/imagebitmap/ImageBitmapOptions.h" #include "core/layout/LayoutHTMLCanvas.h" #include "core/paint/PaintLayer.h" #include "platform/MIMETypeRegistry.h" @@ -1000,14 +1001,14 @@ IntSize HTMLCanvasElement::bitmapSourceSize() const return IntSize(width(), height()); } -ScriptPromise HTMLCanvasElement::createImageBitmap(ScriptState* scriptState, EventTarget& eventTarget, int sx, int sy, int sw, int sh, ExceptionState& exceptionState) +ScriptPromise HTMLCanvasElement::createImageBitmap(ScriptState* scriptState, EventTarget& eventTarget, int sx, int sy, int sw, int sh, const ImageBitmapOptions& options, ExceptionState& exceptionState) { ASSERT(eventTarget.toDOMWindow()); if (!sw || !sh) { exceptionState.throwDOMException(IndexSizeError, String::format("The source %s provided is 0.", sw ? "height" : "width")); return ScriptPromise(); } - return ImageBitmapSource::fulfillImageBitmap(scriptState, isPaintable() ? ImageBitmap::create(this, IntRect(sx, sy, sw, sh)) : nullptr); + return ImageBitmapSource::fulfillImageBitmap(scriptState, isPaintable() ? ImageBitmap::create(this, IntRect(sx, sy, sw, sh), options) : nullptr); } bool HTMLCanvasElement::isOpaque() const diff --git a/third_party/WebKit/Source/core/html/HTMLCanvasElement.h b/third_party/WebKit/Source/core/html/HTMLCanvasElement.h index a4a0f64..24e646d 100644 --- a/third_party/WebKit/Source/core/html/HTMLCanvasElement.h +++ b/third_party/WebKit/Source/core/html/HTMLCanvasElement.h @@ -57,6 +57,7 @@ class CanvasRenderingContextFactory; class GraphicsContext; class HTMLCanvasElement; class Image; +class ImageBitmapOptions; class ImageBuffer; class ImageBufferSurface; class ImageData; @@ -166,7 +167,7 @@ public: // ImageBitmapSource implementation IntSize bitmapSourceSize() const override; - ScriptPromise createImageBitmap(ScriptState*, EventTarget&, int sx, int sy, int sw, int sh, ExceptionState&) override; + ScriptPromise createImageBitmap(ScriptState*, EventTarget&, int sx, int sy, int sw, int sh, const ImageBitmapOptions&, ExceptionState&) override; DECLARE_VIRTUAL_TRACE(); diff --git a/third_party/WebKit/Source/core/html/HTMLImageElement.cpp b/third_party/WebKit/Source/core/html/HTMLImageElement.cpp index 6568ae8..5b7fa06 100644 --- a/third_party/WebKit/Source/core/html/HTMLImageElement.cpp +++ b/third_party/WebKit/Source/core/html/HTMLImageElement.cpp @@ -42,6 +42,7 @@ #include "core/html/HTMLSourceElement.h" #include "core/html/parser/HTMLParserIdioms.h" #include "core/html/parser/HTMLSrcsetParser.h" +#include "core/imagebitmap/ImageBitmapOptions.h" #include "core/inspector/ConsoleMessage.h" #include "core/layout/LayoutBlockFlow.h" #include "core/layout/LayoutImage.h" @@ -684,7 +685,7 @@ void HTMLImageElement::forceReload() const imageLoader().updateFromElement(ImageLoader::UpdateForcedReload, m_referrerPolicy); } -ScriptPromise HTMLImageElement::createImageBitmap(ScriptState* scriptState, EventTarget& eventTarget, int sx, int sy, int sw, int sh, ExceptionState& exceptionState) +ScriptPromise HTMLImageElement::createImageBitmap(ScriptState* scriptState, EventTarget& eventTarget, int sx, int sy, int sw, int sh, const ImageBitmapOptions& options, ExceptionState& exceptionState) { ASSERT(eventTarget.toDOMWindow()); if (!cachedImage()) { @@ -699,7 +700,7 @@ ScriptPromise HTMLImageElement::createImageBitmap(ScriptState* scriptState, Even exceptionState.throwDOMException(IndexSizeError, String::format("The source %s provided is 0.", sw ? "height" : "width")); return ScriptPromise(); } - return ImageBitmapSource::fulfillImageBitmap(scriptState, ImageBitmap::create(this, IntRect(sx, sy, sw, sh), eventTarget.toDOMWindow()->document())); + return ImageBitmapSource::fulfillImageBitmap(scriptState, ImageBitmap::create(this, IntRect(sx, sy, sw, sh), eventTarget.toDOMWindow()->document(), options)); } void HTMLImageElement::selectSourceURL(ImageLoader::UpdateFromElementBehavior behavior) diff --git a/third_party/WebKit/Source/core/html/HTMLImageElement.h b/third_party/WebKit/Source/core/html/HTMLImageElement.h index 1191799..d97b870 100644 --- a/third_party/WebKit/Source/core/html/HTMLImageElement.h +++ b/third_party/WebKit/Source/core/html/HTMLImageElement.h @@ -39,6 +39,7 @@ namespace blink { class HTMLFormElement; class ImageCandidate; class ShadowRoot; +class ImageBitmapOptions; class CORE_EXPORT HTMLImageElement final : public HTMLElement, public CanvasImageSource, public ImageBitmapSource { DEFINE_WRAPPERTYPEINFO(); @@ -119,7 +120,7 @@ public: // ImageBitmapSource implementation IntSize bitmapSourceSize() const override; - ScriptPromise createImageBitmap(ScriptState*, EventTarget&, int sx, int sy, int sw, int sh, ExceptionState&) override; + ScriptPromise createImageBitmap(ScriptState*, EventTarget&, int sx, int sy, int sw, int sh, const ImageBitmapOptions&, ExceptionState&) override; protected: explicit HTMLImageElement(Document&, HTMLFormElement* = 0, bool createdByParser = false); diff --git a/third_party/WebKit/Source/core/html/HTMLVideoElement.cpp b/third_party/WebKit/Source/core/html/HTMLVideoElement.cpp index 38bda79..ab6deeb 100644 --- a/third_party/WebKit/Source/core/html/HTMLVideoElement.cpp +++ b/third_party/WebKit/Source/core/html/HTMLVideoElement.cpp @@ -36,6 +36,7 @@ #include "core/frame/ImageBitmap.h" #include "core/frame/Settings.h" #include "core/html/parser/HTMLParserIdioms.h" +#include "core/imagebitmap/ImageBitmapOptions.h" #include "core/layout/LayoutImage.h" #include "core/layout/LayoutVideo.h" #include "platform/RuntimeEnabledFeatures.h" @@ -325,7 +326,7 @@ IntSize HTMLVideoElement::bitmapSourceSize() const return IntSize(videoWidth(), videoHeight()); } -ScriptPromise HTMLVideoElement::createImageBitmap(ScriptState* scriptState, EventTarget& eventTarget, int sx, int sy, int sw, int sh, ExceptionState& exceptionState) +ScriptPromise HTMLVideoElement::createImageBitmap(ScriptState* scriptState, EventTarget& eventTarget, int sx, int sy, int sw, int sh, const ImageBitmapOptions& options, ExceptionState& exceptionState) { ASSERT(eventTarget.toDOMWindow()); if (networkState() == HTMLMediaElement::NETWORK_EMPTY) { @@ -340,7 +341,7 @@ ScriptPromise HTMLVideoElement::createImageBitmap(ScriptState* scriptState, Even exceptionState.throwDOMException(IndexSizeError, String::format("The source %s provided is 0.", sw ? "height" : "width")); return ScriptPromise(); } - return ImageBitmapSource::fulfillImageBitmap(scriptState, ImageBitmap::create(this, IntRect(sx, sy, sw, sh), eventTarget.toDOMWindow()->document())); + return ImageBitmapSource::fulfillImageBitmap(scriptState, ImageBitmap::create(this, IntRect(sx, sy, sw, sh), eventTarget.toDOMWindow()->document(), options)); } } // namespace blink diff --git a/third_party/WebKit/Source/core/html/HTMLVideoElement.h b/third_party/WebKit/Source/core/html/HTMLVideoElement.h index b7c0dc5..bd0eb79 100644 --- a/third_party/WebKit/Source/core/html/HTMLVideoElement.h +++ b/third_party/WebKit/Source/core/html/HTMLVideoElement.h @@ -39,6 +39,7 @@ namespace blink { class WebGraphicsContext3D; class ExceptionState; class GraphicsContext; +class ImageBitmapOptions; // GL types as defined in OpenGL ES 2.0 header file gl2.h from khronos.org. // That header cannot be included directly due to a conflict with NPAPI headers. @@ -89,7 +90,7 @@ public: // ImageBitmapSource implementation IntSize bitmapSourceSize() const override; - ScriptPromise createImageBitmap(ScriptState*, EventTarget&, int sx, int sy, int sw, int sh, ExceptionState&) override; + ScriptPromise createImageBitmap(ScriptState*, EventTarget&, int sx, int sy, int sw, int sh, const ImageBitmapOptions&, ExceptionState&) override; private: HTMLVideoElement(Document&); diff --git a/third_party/WebKit/Source/core/html/ImageData.cpp b/third_party/WebKit/Source/core/html/ImageData.cpp index 13987f5..5909815 100644 --- a/third_party/WebKit/Source/core/html/ImageData.cpp +++ b/third_party/WebKit/Source/core/html/ImageData.cpp @@ -32,6 +32,7 @@ #include "bindings/core/v8/V8Uint8ClampedArray.h" #include "core/dom/ExceptionCode.h" #include "core/frame/ImageBitmap.h" +#include "core/imagebitmap/ImageBitmapOptions.h" #include "platform/RuntimeEnabledFeatures.h" namespace blink { @@ -146,7 +147,7 @@ ImageData* ImageData::create(DOMUint8ClampedArray* data, unsigned width, unsigne return new ImageData(IntSize(width, height), data); } -ScriptPromise ImageData::createImageBitmap(ScriptState* scriptState, EventTarget& eventTarget, int sx, int sy, int sw, int sh, ExceptionState& exceptionState) +ScriptPromise ImageData::createImageBitmap(ScriptState* scriptState, EventTarget& eventTarget, int sx, int sy, int sw, int sh, const ImageBitmapOptions& options, ExceptionState& exceptionState) { if (!sw || !sh) { exceptionState.throwDOMException(IndexSizeError, String::format("The source %s provided is 0.", sw ? "height" : "width")); @@ -156,7 +157,7 @@ ScriptPromise ImageData::createImageBitmap(ScriptState* scriptState, EventTarget exceptionState.throwDOMException(InvalidStateError, "The source data has been neutered."); return ScriptPromise(); } - return ImageBitmapSource::fulfillImageBitmap(scriptState, ImageBitmap::create(this, IntRect(sx, sy, sw, sh))); + return ImageBitmapSource::fulfillImageBitmap(scriptState, ImageBitmap::create(this, IntRect(sx, sy, sw, sh), options)); } v8::Local<v8::Object> ImageData::associateWithWrapper(v8::Isolate* isolate, const WrapperTypeInfo* wrapperType, v8::Local<v8::Object> wrapper) diff --git a/third_party/WebKit/Source/core/html/ImageData.h b/third_party/WebKit/Source/core/html/ImageData.h index 9c14119..cac3ed6 100644 --- a/third_party/WebKit/Source/core/html/ImageData.h +++ b/third_party/WebKit/Source/core/html/ImageData.h @@ -41,6 +41,7 @@ namespace blink { class ExceptionState; +class ImageBitmapOptions; class CORE_EXPORT ImageData final : public GarbageCollectedFinalized<ImageData>, public ScriptWrappable, public ImageBitmapSource { DEFINE_WRAPPERTYPEINFO(); @@ -59,7 +60,7 @@ public: // ImageBitmapSource implementation IntSize bitmapSourceSize() const override { return m_size; } - ScriptPromise createImageBitmap(ScriptState*, EventTarget&, int sx, int sy, int sw, int sh, ExceptionState&) override; + ScriptPromise createImageBitmap(ScriptState*, EventTarget&, int sx, int sy, int sw, int sh, const ImageBitmapOptions&, ExceptionState&) override; DEFINE_INLINE_TRACE() { } diff --git a/third_party/WebKit/Source/core/imagebitmap/ImageBitmapFactories.cpp b/third_party/WebKit/Source/core/imagebitmap/ImageBitmapFactories.cpp index ce2457d..2d6fa0d 100644 --- a/third_party/WebKit/Source/core/imagebitmap/ImageBitmapFactories.cpp +++ b/third_party/WebKit/Source/core/imagebitmap/ImageBitmapFactories.cpp @@ -39,6 +39,7 @@ #include "core/html/HTMLImageElement.h" #include "core/html/HTMLVideoElement.h" #include "core/html/ImageData.h" +#include "core/imagebitmap/ImageBitmapOptions.h" #include "core/workers/WorkerGlobalScope.h" #include "platform/SharedBuffer.h" #include "platform/graphics/ImageSource.h" @@ -66,26 +67,38 @@ static inline ImageBitmapSource* toImageBitmapSourceInternal(const ImageBitmapSo ScriptPromise ImageBitmapFactories::createImageBitmap(ScriptState* scriptState, EventTarget& eventTarget, const ImageBitmapSourceUnion& bitmapSource, ExceptionState& exceptionState) { + ImageBitmapOptions options; + return createImageBitmap(scriptState, eventTarget, bitmapSource, options, exceptionState); +} + +ScriptPromise ImageBitmapFactories::createImageBitmap(ScriptState* scriptState, EventTarget& eventTarget, const ImageBitmapSourceUnion& bitmapSource, const ImageBitmapOptions& options, ExceptionState& exceptionState) +{ ImageBitmapSource* bitmapSourceInternal = toImageBitmapSourceInternal(bitmapSource); if (bitmapSourceInternal->isBlob()) { Blob* blob = static_cast<Blob*>(bitmapSourceInternal); - ImageBitmapLoader* loader = ImageBitmapFactories::ImageBitmapLoader::create(from(eventTarget), IntRect(), scriptState); + ImageBitmapLoader* loader = ImageBitmapFactories::ImageBitmapLoader::create(from(eventTarget), IntRect(), options, scriptState); ScriptPromise promise = loader->promise(); from(eventTarget).addLoader(loader); loader->loadBlobAsync(eventTarget.executionContext(), blob); return promise; } IntSize srcSize = bitmapSourceInternal->bitmapSourceSize(); - return createImageBitmap(scriptState, eventTarget, bitmapSourceInternal, 0, 0, srcSize.width(), srcSize.height(), exceptionState); + return createImageBitmap(scriptState, eventTarget, bitmapSourceInternal, 0, 0, srcSize.width(), srcSize.height(), options, exceptionState); } ScriptPromise ImageBitmapFactories::createImageBitmap(ScriptState* scriptState, EventTarget& eventTarget, const ImageBitmapSourceUnion& bitmapSource, int sx, int sy, int sw, int sh, ExceptionState& exceptionState) { + ImageBitmapOptions options; + return createImageBitmap(scriptState, eventTarget, bitmapSource, sx, sy, sw, sh, options, exceptionState); +} + +ScriptPromise ImageBitmapFactories::createImageBitmap(ScriptState* scriptState, EventTarget& eventTarget, const ImageBitmapSourceUnion& bitmapSource, int sx, int sy, int sw, int sh, const ImageBitmapOptions& options, ExceptionState& exceptionState) +{ ImageBitmapSource* bitmapSourceInternal = toImageBitmapSourceInternal(bitmapSource); - return createImageBitmap(scriptState, eventTarget, bitmapSourceInternal, sx, sy, sw, sh, exceptionState); + return createImageBitmap(scriptState, eventTarget, bitmapSourceInternal, sx, sy, sw, sh, options, exceptionState); } -ScriptPromise ImageBitmapFactories::createImageBitmap(ScriptState* scriptState, EventTarget& eventTarget, ImageBitmapSource* bitmapSource, int sx, int sy, int sw, int sh, ExceptionState& exceptionState) +ScriptPromise ImageBitmapFactories::createImageBitmap(ScriptState* scriptState, EventTarget& eventTarget, ImageBitmapSource* bitmapSource, int sx, int sy, int sw, int sh, const ImageBitmapOptions& options, ExceptionState& exceptionState) { if (bitmapSource->isBlob()) { if (!sw || !sh) { @@ -93,14 +106,14 @@ ScriptPromise ImageBitmapFactories::createImageBitmap(ScriptState* scriptState, return ScriptPromise(); } Blob* blob = static_cast<Blob*>(bitmapSource); - ImageBitmapLoader* loader = ImageBitmapFactories::ImageBitmapLoader::create(from(eventTarget), IntRect(sx, sy, sw, sh), scriptState); + ImageBitmapLoader* loader = ImageBitmapFactories::ImageBitmapLoader::create(from(eventTarget), IntRect(sx, sy, sw, sh), options, scriptState); ScriptPromise promise = loader->promise(); from(eventTarget).addLoader(loader); loader->loadBlobAsync(eventTarget.executionContext(), blob); return promise; } - return bitmapSource->createImageBitmap(scriptState, eventTarget, sx, sy, sw, sh, exceptionState); + return bitmapSource->createImageBitmap(scriptState, eventTarget, sx, sy, sw, sh, options, exceptionState); } const char* ImageBitmapFactories::supplementName() @@ -139,11 +152,12 @@ void ImageBitmapFactories::didFinishLoading(ImageBitmapLoader* loader) m_pendingLoaders.remove(loader); } -ImageBitmapFactories::ImageBitmapLoader::ImageBitmapLoader(ImageBitmapFactories& factory, const IntRect& cropRect, ScriptState* scriptState) +ImageBitmapFactories::ImageBitmapLoader::ImageBitmapLoader(ImageBitmapFactories& factory, const IntRect& cropRect, ScriptState* scriptState, const ImageBitmapOptions& options) : m_loader(FileReaderLoader::ReadAsArrayBuffer, this) , m_factory(&factory) , m_resolver(ScriptPromiseResolver::create(scriptState)) , m_cropRect(cropRect) + , m_options(options) { } @@ -190,7 +204,7 @@ void ImageBitmapFactories::ImageBitmapLoader::didFinishLoading() m_cropRect = IntRect(IntPoint(), image->size()); } - RefPtrWillBeRawPtr<ImageBitmap> imageBitmap = ImageBitmap::create(image, m_cropRect); + RefPtrWillBeRawPtr<ImageBitmap> imageBitmap = ImageBitmap::create(image, m_cropRect, m_options); m_resolver->resolve(imageBitmap.release()); m_factory->didFinishLoading(this); } diff --git a/third_party/WebKit/Source/core/imagebitmap/ImageBitmapFactories.h b/third_party/WebKit/Source/core/imagebitmap/ImageBitmapFactories.h index 3a311c1..f133854 100644 --- a/third_party/WebKit/Source/core/imagebitmap/ImageBitmapFactories.h +++ b/third_party/WebKit/Source/core/imagebitmap/ImageBitmapFactories.h @@ -37,16 +37,18 @@ #include "bindings/core/v8/UnionTypesCore.h" #include "core/fileapi/FileReaderLoader.h" #include "core/fileapi/FileReaderLoaderClient.h" +#include "core/imagebitmap/ImageBitmapOptions.h" #include "platform/Supplementable.h" #include "platform/geometry/IntRect.h" namespace blink { -class ImageBitmapSource; class Blob; class EventTarget; class ExceptionState; class ExecutionContext; +class ImageBitmapSource; +class ImageBitmapOptions; typedef HTMLImageElementOrHTMLVideoElementOrHTMLCanvasElementOrBlobOrImageDataOrImageBitmap ImageBitmapSourceUnion; @@ -56,8 +58,10 @@ class ImageBitmapFactories final : public NoBaseWillBeGarbageCollectedFinalized< public: static ScriptPromise createImageBitmap(ScriptState*, EventTarget&, const ImageBitmapSourceUnion&, ExceptionState&); + static ScriptPromise createImageBitmap(ScriptState*, EventTarget&, const ImageBitmapSourceUnion&, const ImageBitmapOptions&, ExceptionState&); static ScriptPromise createImageBitmap(ScriptState*, EventTarget&, const ImageBitmapSourceUnion&, int sx, int sy, int sw, int sh, ExceptionState&); - static ScriptPromise createImageBitmap(ScriptState*, EventTarget&, ImageBitmapSource*, int sx, int sy, int sw, int sh, ExceptionState&); + static ScriptPromise createImageBitmap(ScriptState*, EventTarget&, const ImageBitmapSourceUnion&, int sx, int sy, int sw, int sh, const ImageBitmapOptions&, ExceptionState&); + static ScriptPromise createImageBitmap(ScriptState*, EventTarget&, ImageBitmapSource*, int sx, int sy, int sw, int sh, const ImageBitmapOptions&, ExceptionState&); virtual ~ImageBitmapFactories() { } @@ -69,9 +73,9 @@ protected: private: class ImageBitmapLoader final : public GarbageCollectedFinalized<ImageBitmapLoader>, public FileReaderLoaderClient { public: - static ImageBitmapLoader* create(ImageBitmapFactories& factory, const IntRect& cropRect, ScriptState* scriptState) + static ImageBitmapLoader* create(ImageBitmapFactories& factory, const IntRect& cropRect, const ImageBitmapOptions& options, ScriptState* scriptState) { - return new ImageBitmapLoader(factory, cropRect, scriptState); + return new ImageBitmapLoader(factory, cropRect, scriptState, options); } void loadBlobAsync(ExecutionContext*, Blob*); @@ -82,7 +86,7 @@ private: ~ImageBitmapLoader() override { } private: - ImageBitmapLoader(ImageBitmapFactories&, const IntRect&, ScriptState*); + ImageBitmapLoader(ImageBitmapFactories&, const IntRect&, ScriptState*, const ImageBitmapOptions&); void rejectPromise(); @@ -96,6 +100,7 @@ private: RawPtrWillBeMember<ImageBitmapFactories> m_factory; Member<ScriptPromiseResolver> m_resolver; IntRect m_cropRect; + ImageBitmapOptions m_options; }; static ImageBitmapFactories& from(EventTarget&); diff --git a/third_party/WebKit/Source/core/imagebitmap/ImageBitmapFactories.idl b/third_party/WebKit/Source/core/imagebitmap/ImageBitmapFactories.idl index fa642d1..703fc5a 100644 --- a/third_party/WebKit/Source/core/imagebitmap/ImageBitmapFactories.idl +++ b/third_party/WebKit/Source/core/imagebitmap/ImageBitmapFactories.idl @@ -44,7 +44,11 @@ typedef (HTMLImageElement or RuntimeEnabled=ExperimentalCanvasFeatures, ] interface ImageBitmapFactories { [CallWith=ScriptState, RaisesException] Promise createImageBitmap(ImageBitmapSource imageBitmap); + [CallWith=ScriptState, RaisesException, RuntimeEnabled=ExperimentalCanvasFeatures] Promise createImageBitmap( + ImageBitmapSource imageBitmap, ImageBitmapOptions options); [CallWith=ScriptState, RaisesException] Promise createImageBitmap(ImageBitmapSource imageBitmap, long sx, long sy, long sw, long sh); + [CallWith=ScriptState, RaisesException, RuntimeEnabled=ExperimentalCanvasFeatures] Promise createImageBitmap( + ImageBitmapSource imageBitmap, long sx, long sy, long sw, long sh, ImageBitmapOptions options); }; Window implements ImageBitmapFactories; diff --git a/third_party/WebKit/Source/core/imagebitmap/ImageBitmapOptions.idl b/third_party/WebKit/Source/core/imagebitmap/ImageBitmapOptions.idl new file mode 100644 index 0000000..2f54dd07 --- /dev/null +++ b/third_party/WebKit/Source/core/imagebitmap/ImageBitmapOptions.idl @@ -0,0 +1,7 @@ +// Copyright 2016 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +dictionary ImageBitmapOptions { + boolean premuiltiplyAlpha; +}; diff --git a/third_party/WebKit/Source/core/imagebitmap/ImageBitmapSource.cpp b/third_party/WebKit/Source/core/imagebitmap/ImageBitmapSource.cpp index d01c4cd..b80d4b0 100644 --- a/third_party/WebKit/Source/core/imagebitmap/ImageBitmapSource.cpp +++ b/third_party/WebKit/Source/core/imagebitmap/ImageBitmapSource.cpp @@ -5,6 +5,7 @@ #include "core/imagebitmap/ImageBitmapSource.h" #include "core/frame/ImageBitmap.h" +#include "core/imagebitmap/ImageBitmapOptions.h" namespace blink { @@ -20,7 +21,7 @@ ScriptPromise ImageBitmapSource::fulfillImageBitmap(ScriptState* scriptState, Pa return promise; } -ScriptPromise ImageBitmapSource::createImageBitmap(ScriptState* scriptState, EventTarget& eventTarget, int sx, int sy, int sw, int sh, ExceptionState& exceptionState) +ScriptPromise ImageBitmapSource::createImageBitmap(ScriptState* scriptState, EventTarget& eventTarget, int sx, int sy, int sw, int sh, const ImageBitmapOptions& options, ExceptionState& exceptionState) { return ScriptPromise(); } diff --git a/third_party/WebKit/Source/core/imagebitmap/ImageBitmapSource.h b/third_party/WebKit/Source/core/imagebitmap/ImageBitmapSource.h index d0043dd..e319434 100644 --- a/third_party/WebKit/Source/core/imagebitmap/ImageBitmapSource.h +++ b/third_party/WebKit/Source/core/imagebitmap/ImageBitmapSource.h @@ -15,11 +15,12 @@ namespace blink { class ImageBitmap; +class ImageBitmapOptions; class CORE_EXPORT ImageBitmapSource { public: virtual IntSize bitmapSourceSize() const { return IntSize(); } - virtual ScriptPromise createImageBitmap(ScriptState*, EventTarget&, int sx, int sy, int sw, int sh, ExceptionState&); + virtual ScriptPromise createImageBitmap(ScriptState*, EventTarget&, int sx, int sy, int sw, int sh, const ImageBitmapOptions&, ExceptionState&); virtual bool isBlob() const { return false; } |