Diff
Modified: trunk/LayoutTests/ChangeLog (199311 => 199312)
--- trunk/LayoutTests/ChangeLog 2016-04-11 21:32:30 UTC (rev 199311)
+++ trunk/LayoutTests/ChangeLog 2016-04-11 21:33:16 UTC (rev 199312)
@@ -1,3 +1,17 @@
+2016-04-11 Said Abou-Hallawa <sabouhallawa@apple,com>
+
+ Merge CG ImageSource and non CG ImageSource implementation in one file
+ https://bugs.webkit.org/show_bug.cgi?id=155456
+
+ Reviewed by Darin Adler.
+
+ Add a test for image sub-sampling. The image subsampling is enabled by
+ default for iOS platform only. But it can be explicitly enabled through
+ the setting ImageSubsamplingEnabled.
+
+ * fast/images/image-subsampling-expected.html: Added.
+ * fast/images/image-subsampling.html: Added.
+
2016-04-11 Zalan Bujtas <[email protected]>
REGRESSION (r193857): Text selection causes text to disappear.
Added: trunk/LayoutTests/fast/images/image-subsampling-expected.html (0 => 199312)
--- trunk/LayoutTests/fast/images/image-subsampling-expected.html (rev 0)
+++ trunk/LayoutTests/fast/images/image-subsampling-expected.html 2016-04-11 21:33:16 UTC (rev 199312)
@@ -0,0 +1,26 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <style>
+ div {
+ width: 100px;
+ height: 100px;
+ margin: 10px;
+ display: inline-block;
+ }
+ </style>
+<head>
+<body>
+<script>
+ function createDiv(color) {
+ var divElement = document.createElement("div");
+ divElement.style.backgroundColor = color;
+ document.body.appendChild(divElement);
+ }
+
+ createDiv("red");
+ createDiv("green");
+ createDiv("blue");
+</script>
+</body>
+</html>
Added: trunk/LayoutTests/fast/images/image-subsampling.html (0 => 199312)
--- trunk/LayoutTests/fast/images/image-subsampling.html (rev 0)
+++ trunk/LayoutTests/fast/images/image-subsampling.html 2016-04-11 21:33:16 UTC (rev 199312)
@@ -0,0 +1,43 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <style>
+ div {
+ width: 100px;
+ height: 100px;
+ margin: 10px;
+ display: inline-block;
+ }
+ img {
+ width: 100px;
+ height: 100px;
+ }
+ </style>
+<head>
+<body>
+<script>
+ if (window.internals)
+ window.internals.settings.setImageSubsamplingEnabled(true);
+
+ function createImage(color) {
+ var canvas = document.createElement("canvas");
+ canvas.width = 1024 * 3;
+ canvas.height = 1024 * 3;
+ var ctx = canvas.getContext("2d");
+ ctx.fillStyle = color;
+ ctx.fillRect(0, 0, canvas.width, canvas.height);
+
+ var imgElement = document.createElement("img");
+ imgElement.src = ""
+
+ var divElement = document.createElement("div");
+ divElement.appendChild(imgElement);
+ document.body.appendChild(divElement);
+ }
+
+ createImage("red");
+ createImage("green");
+ createImage("blue");
+</script>
+</body>
+</html>
Modified: trunk/Source/WebCore/CMakeLists.txt (199311 => 199312)
--- trunk/Source/WebCore/CMakeLists.txt 2016-04-11 21:32:30 UTC (rev 199311)
+++ trunk/Source/WebCore/CMakeLists.txt 2016-04-11 21:33:16 UTC (rev 199312)
@@ -2213,6 +2213,7 @@
platform/graphics/Image.cpp
platform/graphics/ImageBuffer.cpp
platform/graphics/ImageOrientation.cpp
+ platform/graphics/ImageSource.cpp
platform/graphics/IntPoint.cpp
platform/graphics/IntRect.cpp
platform/graphics/IntSize.cpp
Modified: trunk/Source/WebCore/ChangeLog (199311 => 199312)
--- trunk/Source/WebCore/ChangeLog 2016-04-11 21:32:30 UTC (rev 199311)
+++ trunk/Source/WebCore/ChangeLog 2016-04-11 21:33:16 UTC (rev 199312)
@@ -1,3 +1,166 @@
+2016-04-11 Said Abou-Hallawa <sabouhallawa@apple,com>
+
+ Merge CG ImageSource and non CG ImageSource implementation in one file
+ https://bugs.webkit.org/show_bug.cgi?id=155456
+
+ Reviewed by Darin Adler.
+
+ ImageSource for CG and CG code paths look very similar. All the platform
+ specific code can be moved to ImageDecoder classes for CG and non CG. And
+ we can have the ImageSource be platform independent and we get rid of
+ ImageSourceCG.cpp.
+
+ Test: fast/images/image-subsampling.html
+
+ * CMakeLists.txt:
+ * PlatformAppleWin.cmake:
+ * PlatformMac.cmake:
+ * WebCore.xcodeproj/project.pbxproj:
+ Delete ImageSourceCG.cpp form all make files and add ImageSource.cpp to
+ CMakeLists.txt.
+
+ * platform/Cursor.cpp:
+ (WebCore::determineHotSpot):
+ * platform/graphics/BitmapImage.cpp:
+ (WebCore::BitmapImage::hotSpot):
+ (WebCore::BitmapImage::getHotSpot): Deleted.
+ * platform/graphics/BitmapImage.h:
+ * platform/graphics/Image.h:
+ (WebCore::Image::hotSpot):
+ (WebCore::Image::getHotSpot): Deleted.
+ Rename getHotSpot() to hotSpot() and change it to return Optional<IntPoint>.
+
+ * platform/graphics/ImageSource.cpp:
+ (WebCore::ImageSource::~ImageSource): Remove clear(true) call. It does nothing.
+ (WebCore::ImageSource::clearFrameBufferCache): A wrapper which calls ImageDecoder::clearFrameBufferCache().
+ (WebCore::ImageSource::clear): Calls clearFrameBufferCache() which will do nothing for CG.
+
+ (WebCore::ImageSource::ensureDecoderIsCreated): Change SharedBuffer* to
+ const SharedBuffer& and remove the call to ImageDecoder::setMaxNumPixels().
+ The value of const static int CG ImageDecoder::m_maxNumPixels will be set
+ based on IMAGE_DECODER_DOWN_SAMPLING.
+
+ (WebCore::ImageSource::setData): Pass SharedBuffer& to the underlying functions.
+
+ (WebCore::ImageSource::calculateMaximumSubsamplingLevel): Returns the maximum
+ subsampling level allowed for an image.
+
+ (WebCore::ImageSource::subsamplingLevelForScale): Converts from a scale to
+ SubsamplingLevel taking into consideration the maximumSubsamplingLevel for
+ a particular image.
+
+ (WebCore::ImageSource::bytesDecodedToDetermineProperties): Returns the number
+ of encoded bytes which can determine the image properties. For non CG it's
+ zero. For CG it is a maximum value which can be corrected later.
+
+ (WebCore::ImageSource::isSizeAvailable):
+ (WebCore::ImageSource::sizeRespectingOrientation):
+ (WebCore::ImageSource::frameCount):
+ (WebCore::ImageSource::repetitionCount):
+ (WebCore::ImageSource::filenameExtension):
+ (WebCore::ImageSource::getHotSpot):
+ (WebCore::ImageSource::frameIsCompleteAtIndex):
+ (WebCore::ImageSource::frameHasAlphaAtIndex):
+ (WebCore::ImageSource::allowSubsamplingOfFrameAtIndex):
+ (WebCore::ImageSource::frameSizeAtIndex):
+ (WebCore::ImageSource::frameBytesAtIndex):
+ (WebCore::ImageSource::frameDurationAtIndex):
+ (WebCore::ImageSource::orientationAtIndex):
+ (WebCore::ImageSource::createFrameImageAtIndex):
+ These are wrappers for the ImageDecoder APIs. The purpose of these functions
+ is to ensure the ImageDecoder is created.
+
+ (WebCore::ImageSource::dump): Called from BitmapImage::dump().
+
+ (WebCore::ImageSource::getHotSpot): Deleted.
+
+ * platform/graphics/ImageSource.h:
+ (WebCore::ImageSource::setAllowSubsampling): Called from BitmapImage::setAllowSubsampling().
+
+ (WebCore::ImageSource::maxPixelsPerDecodedImage): Deleted.
+ (WebCore::ImageSource::setMaxPixelsPerDecodedImage): Deleted.
+ Setting maxPixelsPerDecodedImage was moved to the non CG ImageDecoder.
+
+ * platform/graphics/cg/ImageDecoderCG.cpp:
+ (WebCore::ImageDecoder::setData): Change SharedBuffer* to SharedBuffer&.
+
+ (WebCore::ImageDecoder::subsamplingLevelForScale): Deleted.
+ The code was moved to ImageSource::subsamplingLevelForScale().
+
+ * platform/graphics/cg/ImageDecoderCG.h:
+ (WebCore::ImageDecoder::create): Make the prototype of this function
+ suitable for CG and non CG cases.
+ (WebCore::ImageDecoder::clearFrameBufferCache): Empty functions for CG.
+
+ * platform/graphics/cg/ImageSourceCG.cpp: Removed.
+
+ * platform/image-decoders/ImageDecoder.cpp:
+ (WebCore::ImageDecoder::frameIsCompleteAtIndex): A mew function to return
+ whether the frame decoding is complete or not.
+
+ (WebCore::ImageDecoder::frameHasAlphaAtIndex): Simplify the logic.
+
+ (WebCore::ImageDecoder::frameDurationAtIndex): The code was moved from
+ ImageSource::frameDurationAtIndex() in ImageSource.cpp.
+
+ (WebCore::ImageDecoder::createFrameImageAtIndex): The code was moved from
+ ImageSource::createFrameImageAtIndex() in ImageSource.cpp.
+
+ * platform/image-decoders/ImageDecoder.h:
+ (WebCore::ImageDecoder::ImageDecoder): Initialize the members in class.
+ (WebCore::ImageDecoder::~ImageDecoder): Fix the braces style.
+ (WebCore::ImageDecoder::setData): Change the type of the argument from
+ SharedBuffer* to SharedBuffer&.
+ (WebCore::ImageDecoder::frameSizeAtIndex): Add the argument SubsamplingLevel
+ so it can have the same prototype as CG.
+ (WebCore::ImageDecoder::orientationAtIndex): Rename it to the same of CG.
+
+ (WebCore::ImageDecoder::allowSubsamplingOfFrameAtIndex):
+ (WebCore::ImageDecoder::bytesDecodedToDetermineProperties):
+ (WebCore::ImageDecoder::subsamplingLevelForScale): Add these functions
+ and return the default values so we do not have to add directive compiled
+ non CG blocks in ImageSource.cpp.
+
+ (WebCore::ImageDecoder::hotSpot): Return Optional<IntPoint>.
+
+ (WebCore::ImageDecoder::orientation): Deleted.
+ (WebCore::ImageDecoder::setMaxNumPixels): Deleted.
+
+ * platform/image-decoders/bmp/BMPImageDecoder.cpp:
+ (WebCore::BMPImageDecoder::setData):
+ * platform/image-decoders/bmp/BMPImageDecoder.h:
+ * platform/image-decoders/gif/GIFImageDecoder.cpp:
+ (WebCore::GIFImageDecoder::setData):
+ (WebCore::GIFImageDecoder::decode):
+ * platform/image-decoders/gif/GIFImageDecoder.h:
+ * platform/image-decoders/gif/GIFImageReader.h:
+ (GIFImageReader::setData):
+ * platform/image-decoders/ico/ICOImageDecoder.cpp:
+ (WebCore::ICOImageDecoder::setData):
+ Use reference SharedBuffer instead of pointer SharedBuffer.
+
+ (WebCore::ICOImageDecoder::hotSpot):
+ (WebCore::ICOImageDecoder::hotSpotAtIndex):
+ Change hotSpot() to return Optional<IntPoint>.
+ * platform/image-decoders/ico/ICOImageDecoder.h:
+
+ (WebCore::ICOImageDecoder::setDataForPNGDecoderAtIndex):
+ Pass reference SharedBuffer instead of pointer SharedBuffer.
+
+2016-04-08 Said Abou-Hallawa <sabouhallawa@apple,com>
+
+ Timing attack on SVG feComposite filter circumvents same-origin policy
+ https://bugs.webkit.org/show_bug.cgi?id=154338
+
+ Reviewed by Oliver Hunt.
+
+ Ensure the FEComposite arithmetic filter is clamping the resulted color
+ components in a constant time.
+
+ * platform/graphics/filters/FEComposite.cpp:
+ (WebCore::clampByte):
+ (WebCore::computeArithmeticPixels):
+
2016-04-11 Brady Eidson <[email protected]>
Clean up IDBBindingUtilities.
Modified: trunk/Source/WebCore/PlatformAppleWin.cmake (199311 => 199312)
--- trunk/Source/WebCore/PlatformAppleWin.cmake 2016-04-11 21:32:30 UTC (rev 199311)
+++ trunk/Source/WebCore/PlatformAppleWin.cmake 2016-04-11 21:33:16 UTC (rev 199312)
@@ -72,7 +72,6 @@
platform/graphics/cg/ImageBufferDataCG.cpp
platform/graphics/cg/ImageCG.cpp
platform/graphics/cg/ImageDecoderCG.cpp
- platform/graphics/cg/ImageSourceCG.cpp
platform/graphics/cg/ImageSourceCGWin.cpp
platform/graphics/cg/IntPointCG.cpp
platform/graphics/cg/IntRectCG.cpp
Modified: trunk/Source/WebCore/PlatformMac.cmake (199311 => 199312)
--- trunk/Source/WebCore/PlatformMac.cmake 2016-04-11 21:32:30 UTC (rev 199311)
+++ trunk/Source/WebCore/PlatformMac.cmake 2016-04-11 21:33:16 UTC (rev 199312)
@@ -406,7 +406,6 @@
platform/graphics/cg/ImageBufferDataCG.cpp
platform/graphics/cg/ImageCG.cpp
platform/graphics/cg/ImageDecoderCG.cpp
- platform/graphics/cg/ImageSourceCG.cpp
platform/graphics/cg/ImageSourceCGMac.mm
platform/graphics/cg/IntPointCG.cpp
platform/graphics/cg/IntRectCG.cpp
Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (199311 => 199312)
--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2016-04-11 21:32:30 UTC (rev 199311)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2016-04-11 21:33:16 UTC (rev 199312)
@@ -4984,7 +4984,6 @@
B275355A0B053814002CE64F /* FloatRectCG.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B275352C0B053814002CE64F /* FloatRectCG.cpp */; };
B275355B0B053814002CE64F /* FloatSizeCG.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B275352D0B053814002CE64F /* FloatSizeCG.cpp */; };
B275355E0B053814002CE64F /* ImageCG.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B27535300B053814002CE64F /* ImageCG.cpp */; };
- B275355F0B053814002CE64F /* ImageSourceCG.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B27535310B053814002CE64F /* ImageSourceCG.cpp */; };
B27535600B053814002CE64F /* IntPointCG.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B27535320B053814002CE64F /* IntPointCG.cpp */; };
B27535610B053814002CE64F /* IntRectCG.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B27535330B053814002CE64F /* IntRectCG.cpp */; };
B27535620B053814002CE64F /* IntSizeCG.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B27535340B053814002CE64F /* IntSizeCG.cpp */; };
@@ -12873,7 +12872,6 @@
B275352C0B053814002CE64F /* FloatRectCG.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = FloatRectCG.cpp; sourceTree = "<group>"; };
B275352D0B053814002CE64F /* FloatSizeCG.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = FloatSizeCG.cpp; sourceTree = "<group>"; };
B27535300B053814002CE64F /* ImageCG.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = ImageCG.cpp; sourceTree = "<group>"; };
- B27535310B053814002CE64F /* ImageSourceCG.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = ImageSourceCG.cpp; sourceTree = "<group>"; };
B27535320B053814002CE64F /* IntPointCG.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = IntPointCG.cpp; sourceTree = "<group>"; };
B27535330B053814002CE64F /* IntRectCG.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = IntRectCG.cpp; sourceTree = "<group>"; };
B27535340B053814002CE64F /* IntSizeCG.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = IntSizeCG.cpp; sourceTree = "<group>"; };
@@ -21779,7 +21777,6 @@
B27535300B053814002CE64F /* ImageCG.cpp */,
555B87EA1CAAF0AB00349425 /* ImageDecoderCG.cpp */,
555B87EB1CAAF0AB00349425 /* ImageDecoderCG.h */,
- B27535310B053814002CE64F /* ImageSourceCG.cpp */,
4B3480920EEF50D400AC1B41 /* ImageSourceCG.h */,
4B3480910EEF50D400AC1B41 /* ImageSourceCGMac.mm */,
B27535320B053814002CE64F /* IntPointCG.cpp */,
@@ -29996,7 +29993,6 @@
2D5A592F152525230036EE51 /* ImageOrientation.cpp in Sources */,
B51A2F4117D7D5DE0072517A /* ImageQualityController.cpp in Sources */,
0F3C725E1974874B00AEDD0C /* ImageSource.cpp in Sources */,
- B275355F0B053814002CE64F /* ImageSourceCG.cpp in Sources */,
4B3480930EEF50D400AC1B41 /* ImageSourceCGMac.mm in Sources */,
316FE1170E6E1DA700BF6088 /* ImplicitAnimation.cpp in Sources */,
BE961C5418AD338500D07DC5 /* InbandDataTextTrack.cpp in Sources */,
Modified: trunk/Source/WebCore/platform/Cursor.cpp (199311 => 199312)
--- trunk/Source/WebCore/platform/Cursor.cpp 2016-04-11 21:32:30 UTC (rev 199311)
+++ trunk/Source/WebCore/platform/Cursor.cpp 2016-04-11 21:33:16 UTC (rev 199312)
@@ -44,10 +44,10 @@
return specifiedHotSpot;
// If hot spot is not specified externally, it can be extracted from some image formats (e.g. .cur).
- IntPoint intrinsicHotSpot;
- bool imageHasIntrinsicHotSpot = image->getHotSpot(intrinsicHotSpot);
- if (imageHasIntrinsicHotSpot && imageRect.contains(intrinsicHotSpot))
- return intrinsicHotSpot;
+ if (auto intrinsicHotSpot = image->hotSpot()) {
+ if (imageRect.contains(intrinsicHotSpot.value()))
+ return intrinsicHotSpot.value();
+ }
return IntPoint();
}
Modified: trunk/Source/WebCore/platform/graphics/BitmapImage.cpp (199311 => 199312)
--- trunk/Source/WebCore/platform/graphics/BitmapImage.cpp 2016-04-11 21:32:30 UTC (rev 199311)
+++ trunk/Source/WebCore/platform/graphics/BitmapImage.cpp 2016-04-11 21:33:16 UTC (rev 199312)
@@ -254,9 +254,9 @@
return m_sizeRespectingOrientation;
}
-bool BitmapImage::getHotSpot(IntPoint& hotSpot) const
+Optional<IntPoint> BitmapImage::hotSpot() const
{
- bool result = m_source.getHotSpot(hotSpot);
+ auto result = m_source.hotSpot();
didDecodeProperties();
return result;
}
Modified: trunk/Source/WebCore/platform/graphics/BitmapImage.h (199311 => 199312)
--- trunk/Source/WebCore/platform/graphics/BitmapImage.h 2016-04-11 21:32:30 UTC (rev 199311)
+++ trunk/Source/WebCore/platform/graphics/BitmapImage.h 2016-04-11 21:33:16 UTC (rev 199312)
@@ -125,7 +125,7 @@
FloatSize size() const override;
IntSize sizeRespectingOrientation() const;
- bool getHotSpot(IntPoint&) const override;
+ Optional<IntPoint> hotSpot() const override;
unsigned decodedSize() const { return m_decodedSize; }
Modified: trunk/Source/WebCore/platform/graphics/Image.h (199311 => 199312)
--- trunk/Source/WebCore/platform/graphics/Image.h 2016-04-11 21:32:30 UTC (rev 199311)
+++ trunk/Source/WebCore/platform/graphics/Image.h 2016-04-11 21:33:16 UTC (rev 199312)
@@ -33,6 +33,7 @@
#include "GraphicsTypes.h"
#include "ImageOrientation.h"
#include "NativeImagePtr.h"
+#include <wtf/Optional.h>
#include <wtf/PassRefPtr.h>
#include <wtf/RefCounted.h>
#include <wtf/RefPtr.h>
@@ -107,7 +108,7 @@
FloatRect rect() const { return FloatRect(FloatPoint(), size()); }
float width() const { return size().width(); }
float height() const { return size().height(); }
- virtual bool getHotSpot(IntPoint&) const { return false; }
+ virtual Optional<IntPoint> hotSpot() const { return Nullopt; }
#if PLATFORM(IOS)
virtual FloatSize originalSize() const { return size(); }
Modified: trunk/Source/WebCore/platform/graphics/ImageSource.cpp (199311 => 199312)
--- trunk/Source/WebCore/platform/graphics/ImageSource.cpp 2016-04-11 21:32:30 UTC (rev 199311)
+++ trunk/Source/WebCore/platform/graphics/ImageSource.cpp 2016-04-11 21:33:16 UTC (rev 199312)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2006 Apple Inc. All rights reserved.
+ * Copyright (C) 2006, 2010, 2011, 2012, 2014, 2016 Apple Inc. All rights reserved.
* Copyright (C) 2007 Alp Toker <[email protected]>
* Copyright (C) 2008, Google Inc. All rights reserved.
* Copyright (C) 2007-2009 Torch Mobile, Inc
@@ -29,19 +29,16 @@
#include "config.h"
#include "ImageSource.h"
-#if !USE(CG)
-
+#if USE(CG)
+#include "ImageDecoderCG.h"
+#else
#include "ImageDecoder.h"
+#endif
#include "ImageOrientation.h"
-#include "NotImplemented.h"
namespace WebCore {
-#if ENABLE(IMAGE_DECODER_DOWN_SAMPLING)
-unsigned ImageSource::s_maxPixelsPerDecodedImage = 1024 * 1024;
-#endif
-
ImageSource::ImageSource(ImageSource::AlphaOption alphaOption, ImageSource::GammaAndColorProfileOption gammaAndColorProfileOption)
: m_alphaOption(alphaOption)
, m_gammaAndColorProfileOption(gammaAndColorProfileOption)
@@ -50,15 +47,22 @@
ImageSource::~ImageSource()
{
- clear(true);
}
-void ImageSource::clear(bool destroyAll, size_t clearBeforeFrame, SharedBuffer* data, bool allDataReceived)
+void ImageSource::clearFrameBufferCache(size_t clearBeforeFrame)
{
- if (!destroyAll) {
- if (m_decoder)
- m_decoder->clearFrameBufferCache(clearBeforeFrame);
+ if (!initialized())
return;
+ m_decoder->clearFrameBufferCache(clearBeforeFrame);
+}
+
+void ImageSource::clear(bool destroyAllFrames, size_t clearBeforeFrame, SharedBuffer* data, bool allDataReceived)
+{
+ // There's no need to throw away the decoder unless we're explicitly asked
+ // to destroy all of the frames.
+ if (!destroyAllFrames) {
+ clearFrameBufferCache(clearBeforeFrame);
+ return;
}
m_decoder = nullptr;
@@ -67,20 +71,12 @@
setData(data, allDataReceived);
}
-void ImageSource::ensureDecoderIsCreated(SharedBuffer* data)
+void ImageSource::ensureDecoderIsCreated(const SharedBuffer& data)
{
if (initialized())
return;
- // Make the decoder by sniffing the bytes.
- // This method will examine the data and instantiate an instance of the appropriate decoder plugin.
- // If insufficient bytes are available to determine the image type, no decoder plugin will be
- // made.
- m_decoder = ImageDecoder::create(*data, m_alphaOption, m_gammaAndColorProfileOption);
-#if ENABLE(IMAGE_DECODER_DOWN_SAMPLING)
- if (m_decoder && s_maxPixelsPerDecodedImage)
- m_decoder->setMaxNumPixels(s_maxPixelsPerDecodedImage);
-#endif
+ m_decoder = ImageDecoder::create(data, m_alphaOption, m_gammaAndColorProfileOption);
}
void ImageSource::setData(SharedBuffer* data, bool allDataReceived)
@@ -88,7 +84,7 @@
if (!data)
return;
- ensureDecoderIsCreated(data);
+ ensureDecoderIsCreated(*data);
if (!initialized()) {
ASSERT_NOT_REACHED();
@@ -96,25 +92,48 @@
}
if (m_decoder)
- m_decoder->setData(data, allDataReceived);
+ m_decoder->setData(*data, allDataReceived);
}
-String ImageSource::filenameExtension() const
+SubsamplingLevel ImageSource::calculateMaximumSubsamplingLevel() const
{
- return m_decoder ? m_decoder->filenameExtension() : String();
+ if (!m_allowSubsampling || !allowSubsamplingOfFrameAtIndex(0))
+ return 0;
+
+ // FIXME: this value was chosen to be appropriate for iOS since the image
+ // subsampling is only enabled by default on iOS. Choose a different value
+ // if image subsampling is enabled on other platform.
+ const int maximumImageAreaBeforeSubsampling = 5 * 1024 * 1024;
+ const SubsamplingLevel maxSubsamplingLevel = 3;
+
+ for (SubsamplingLevel level = 0; level < maxSubsamplingLevel; ++level) {
+ if (frameSizeAtIndex(0, level).area() < maximumImageAreaBeforeSubsampling)
+ return level;
+ }
+
+ return maxSubsamplingLevel;
}
-SubsamplingLevel ImageSource::subsamplingLevelForScale(float) const
+SubsamplingLevel ImageSource::subsamplingLevelForScale(float scale) const
{
- return 0;
+ if (!(scale > 0 && scale <= 1))
+ return 0;
+
+ SubsamplingLevel maximumSubsamplingLevel = calculateMaximumSubsamplingLevel();
+ if (!maximumSubsamplingLevel)
+ return 0;
+
+ // There are four subsampling levels: 0 = 1x, 1 = 0.5x, 2 = 0.25x, 3 = 0.125x.
+ SubsamplingLevel result = std::ceil(std::log2(1 / scale));
+ return std::min(result, maximumSubsamplingLevel);
}
-bool ImageSource::allowSubsamplingOfFrameAtIndex(size_t) const
+size_t ImageSource::bytesDecodedToDetermineProperties()
{
- return false;
+ return ImageDecoder::bytesDecodedToDetermineProperties();
}
-bool ImageSource::isSizeAvailable()
+bool ImageSource::isSizeAvailable() const
{
return initialized() && m_decoder->isSizeAvailable();
}
@@ -129,97 +148,71 @@
return frameSizeAtIndex(0, 0, RespectImageOrientation);
}
-IntSize ImageSource::frameSizeAtIndex(size_t index, SubsamplingLevel, RespectImageOrientationEnum shouldRespectImageOrientation) const
+size_t ImageSource::frameCount() const
{
- if (!initialized())
- return { };
-
- IntSize size = m_decoder->frameSizeAtIndex(index);
- ImageOrientation orientation = m_decoder->orientation();
-
- return shouldRespectImageOrientation == RespectImageOrientation && orientation.usesWidthAsHeight() ? size.transposedSize() : size;
+ return initialized() ? m_decoder->frameCount() : 0;
}
-bool ImageSource::getHotSpot(IntPoint& hotSpot) const
+int ImageSource::repetitionCount()
{
- return initialized() && m_decoder->hotSpot(hotSpot);
+ return initialized() ? m_decoder->repetitionCount() : cAnimationNone;
}
-size_t ImageSource::bytesDecodedToDetermineProperties() const
+String ImageSource::filenameExtension() const
{
- return 0;
+ return initialized() ? m_decoder->filenameExtension() : String();
}
-int ImageSource::repetitionCount()
+Optional<IntPoint> ImageSource::hotSpot() const
{
- return initialized() ? m_decoder->repetitionCount() : cAnimationNone;
+ return initialized() ? m_decoder->hotSpot() : Nullopt;
}
-size_t ImageSource::frameCount() const
+bool ImageSource::frameIsCompleteAtIndex(size_t index)
{
- return initialized() ? m_decoder->frameCount() : 0;
+ return initialized() && m_decoder->frameIsCompleteAtIndex(index);
}
-NativeImagePtr ImageSource::createFrameImageAtIndex(size_t index, SubsamplingLevel)
+bool ImageSource::frameHasAlphaAtIndex(size_t index)
{
- if (!initialized())
- return nullptr;
+ return !initialized() || m_decoder->frameHasAlphaAtIndex(index);
+}
- // Zero-height images can cause problems for some ports. If we have an
- // empty image dimension, just bail.
- if (size().isEmpty())
- return nullptr;
-
- ImageFrame* buffer = m_decoder->frameBufferAtIndex(index);
- if (!buffer || buffer->status() == ImageFrame::FrameEmpty)
- return nullptr;
-
- // Return the buffer contents as a native image. For some ports, the data
- // is already in a native container, and this just increments its refcount.
- return buffer->asNewNativeImage();
+bool ImageSource::allowSubsamplingOfFrameAtIndex(size_t index) const
+{
+ return initialized() && m_decoder->allowSubsamplingOfFrameAtIndex(index);
}
-float ImageSource::frameDurationAtIndex(size_t index)
+IntSize ImageSource::frameSizeAtIndex(size_t index, SubsamplingLevel subsamplingLevel, RespectImageOrientationEnum shouldRespectImageOrientation) const
{
if (!initialized())
- return 0;
+ return { };
- ImageFrame* buffer = m_decoder->frameBufferAtIndex(index);
- if (!buffer || buffer->status() == ImageFrame::FrameEmpty)
- return 0;
+ IntSize size = m_decoder->frameSizeAtIndex(index, subsamplingLevel);
+ if (shouldRespectImageOrientation != RespectImageOrientation)
+ return size;
- // Many annoying ads specify a 0 duration to make an image flash as quickly as possible.
- // We follow Firefox's behavior and use a duration of 100 ms for any frames that specify
- // a duration of <= 10 ms. See <rdar://problem/7689300> and <http://webkit.org/b/36082>
- // for more information.
- const float duration = buffer->duration() / 1000.0f;
- if (duration < 0.011f)
- return 0.100f;
- return duration;
+ return orientationAtIndex(index).usesWidthAsHeight() ? size.transposedSize() : size;
}
-ImageOrientation ImageSource::orientationAtIndex(size_t) const
+unsigned ImageSource::frameBytesAtIndex(size_t index, SubsamplingLevel subsamplingLevel) const
{
- return initialized() ? m_decoder->orientation() : ImageOrientation();
+ return frameSizeAtIndex(index, subsamplingLevel).area() * 4;
}
-bool ImageSource::frameHasAlphaAtIndex(size_t index)
+float ImageSource::frameDurationAtIndex(size_t index)
{
- return !initialized() || m_decoder->frameHasAlphaAtIndex(index);
+ return initialized() ? m_decoder->frameDurationAtIndex(index) : 0;
}
-bool ImageSource::frameIsCompleteAtIndex(size_t index)
+ImageOrientation ImageSource::orientationAtIndex(size_t index) const
{
- if (!initialized())
- return false;
-
- ImageFrame* buffer = m_decoder->frameBufferAtIndex(index);
- return buffer && buffer->status() == ImageFrame::FrameComplete;
+ return initialized() ? m_decoder->orientationAtIndex(index) : ImageOrientation();
}
-
-unsigned ImageSource::frameBytesAtIndex(size_t index, SubsamplingLevel) const
+
+NativeImagePtr ImageSource::createFrameImageAtIndex(size_t index, SubsamplingLevel subsamplingLevel)
{
- return initialized() ? m_decoder->frameBytesAtIndex(index) : 0;
+ return initialized() ? m_decoder->createFrameImageAtIndex(index, subsamplingLevel) : nullptr;
}
void ImageSource::dump(TextStream& ts) const
@@ -233,5 +226,3 @@
}
}
-
-#endif // USE(CG)
Modified: trunk/Source/WebCore/platform/graphics/ImageSource.h (199311 => 199312)
--- trunk/Source/WebCore/platform/graphics/ImageSource.h 2016-04-11 21:32:30 UTC (rev 199311)
+++ trunk/Source/WebCore/platform/graphics/ImageSource.h 2016-04-11 21:33:16 UTC (rev 199312)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2004, 2005, 2006 Apple Inc. All rights reserved.
+ * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2010, 2012, 2014, 2016 Apple Inc. All rights reserved.
* Copyright (C) 2007-2008 Torch Mobile, Inc.
*
* Redistribution and use in source and binary forms, with or without
@@ -28,18 +28,15 @@
#define ImageSource_h
#include "ImageOrientation.h"
+#include "IntPoint.h"
#include "NativeImagePtr.h"
#include "TextStream.h"
#include <wtf/Forward.h>
#include <wtf/Noncopyable.h>
+#include <wtf/Optional.h>
#include <wtf/Vector.h>
-#if USE(CG)
-typedef struct CGImageSource* CGImageSourceRef;
-typedef const struct __CFData* CFDataRef;
-#endif
-
namespace WebCore {
class ImageOrientation;
@@ -83,7 +80,7 @@
GammaAndColorProfileIgnored
};
- ImageSource(AlphaOption alphaOption = AlphaPremultiplied, GammaAndColorProfileOption gammaAndColorProfileOption = GammaAndColorProfileApplied);
+ ImageSource(AlphaOption = AlphaPremultiplied, GammaAndColorProfileOption = GammaAndColorProfileApplied);
~ImageSource();
// Tells the ImageSource that the Image no longer cares about decoded frame
@@ -107,76 +104,61 @@
// who set |destroyAll| to true if they wish to be able to continue using
// the ImageSource. This way implementations which choose to destroy their
// decoders in some cases can reconstruct them correctly.
- void clear(bool destroyAll,
- size_t clearBeforeFrame = 0,
- SharedBuffer* data = ""
- bool allDataReceived = false);
+ void clear(bool destroyAll, size_t clearBeforeFrame = 0, SharedBuffer* data = "" bool allDataReceived = false);
bool initialized() const { return m_decoder.get(); }
void setData(SharedBuffer* data, bool allDataReceived);
- String filenameExtension() const;
SubsamplingLevel subsamplingLevelForScale(float) const;
- bool allowSubsamplingOfFrameAtIndex(size_t) const;
void setAllowSubsampling(bool allowSubsampling) { m_allowSubsampling = allowSubsampling; }
- SubsamplingLevel maximumSubsamplingLevel() const;
-
- bool isSizeAvailable();
+ static size_t bytesDecodedToDetermineProperties();
+ bool isSizeAvailable() const;
// Always original size, without subsampling.
IntSize size() const;
IntSize sizeRespectingOrientation() const;
-
- // Size of optionally subsampled frame.
- IntSize frameSizeAtIndex(size_t, SubsamplingLevel = 0, RespectImageOrientationEnum = DoNotRespectImageOrientation) const;
- bool getHotSpot(IntPoint&) const;
-
- size_t bytesDecodedToDetermineProperties() const;
-
+ size_t frameCount() const;
int repetitionCount();
+ String filenameExtension() const;
+ Optional<IntPoint> hotSpot() const;
- size_t frameCount() const;
-
- // Callers should not call this after calling clear() with a higher index;
- // see comments on clear() above.
- NativeImagePtr createFrameImageAtIndex(size_t, SubsamplingLevel = 0);
-
- float frameDurationAtIndex(size_t);
- bool frameHasAlphaAtIndex(size_t); // Whether or not the frame actually used any alpha.
bool frameIsCompleteAtIndex(size_t); // Whether or not the frame is completely decoded.
- ImageOrientation orientationAtIndex(size_t) const; // EXIF image orientation
-
+ bool frameHasAlphaAtIndex(size_t); // Whether or not the frame actually used any alpha.
+ bool allowSubsamplingOfFrameAtIndex(size_t) const;
+
+ // Size of optionally subsampled frame.
+ IntSize frameSizeAtIndex(size_t, SubsamplingLevel = 0, RespectImageOrientationEnum = DoNotRespectImageOrientation) const;
+
// Return the number of bytes in the decoded frame. If the frame is not yet
// decoded then return 0.
unsigned frameBytesAtIndex(size_t, SubsamplingLevel = 0) const;
-
-#if ENABLE(IMAGE_DECODER_DOWN_SAMPLING)
- static unsigned maxPixelsPerDecodedImage() { return s_maxPixelsPerDecodedImage; }
- static void setMaxPixelsPerDecodedImage(unsigned maxPixels) { s_maxPixelsPerDecodedImage = maxPixels; }
-#endif
-
+
+ float frameDurationAtIndex(size_t);
+ ImageOrientation orientationAtIndex(size_t) const; // EXIF image orientation
+
+ // Callers should not call this after calling clear() with a higher index;
+ // see comments on clear() above.
+ NativeImagePtr createFrameImageAtIndex(size_t, SubsamplingLevel = 0);
+
private:
- void ensureDecoderIsCreated(SharedBuffer*);
+ void clearFrameBufferCache(size_t);
+ void ensureDecoderIsCreated(const SharedBuffer&);
SubsamplingLevel calculateMaximumSubsamplingLevel() const;
void dump(TextStream&) const;
std::unique_ptr<ImageDecoder> m_decoder;
-
+
+ // The default value of m_allowSubsampling should be the same as defaultImageSubsamplingEnabled in Settings.cpp
#if PLATFORM(IOS)
bool m_allowSubsampling { true };
#else
bool m_allowSubsampling { false };
#endif
-#if !USE(CG)
AlphaOption m_alphaOption;
GammaAndColorProfileOption m_gammaAndColorProfileOption;
-#endif
-#if ENABLE(IMAGE_DECODER_DOWN_SAMPLING)
- static unsigned s_maxPixelsPerDecodedImage;
-#endif
};
}
Modified: trunk/Source/WebCore/platform/graphics/cg/ImageDecoderCG.cpp (199311 => 199312)
--- trunk/Source/WebCore/platform/graphics/cg/ImageDecoderCG.cpp 2016-04-11 21:32:30 UTC (rev 199311)
+++ trunk/Source/WebCore/platform/graphics/cg/ImageDecoderCG.cpp 2016-04-11 21:33:16 UTC (rev 199312)
@@ -122,15 +122,6 @@
m_nativeDecoder = adoptCF(CGImageSourceCreateIncremental(nullptr));
}
-SubsamplingLevel ImageDecoder::subsamplingLevelForScale(float scale, SubsamplingLevel maximumSubsamplingLevel)
-{
- // There are four subsampling levels: 0 = 1x, 1 = 0.5x, 2 = 0.25x, 3 = 0.125x.
- float clampedScale = std::max<float>(0.125, std::min<float>(1, scale));
- SubsamplingLevel result = ceilf(log2f(1 / clampedScale));
- ASSERT(result >=0 && result <= 3);
- return std::min(result, maximumSubsamplingLevel);
-}
-
size_t ImageDecoder::bytesDecodedToDetermineProperties()
{
// Measured by tracing malloc/calloc calls on Mac OS 10.6.6, x86_64.
@@ -210,26 +201,25 @@
return cAnimationNone;
}
-bool ImageDecoder::hotSpot(IntPoint& hotSpot) const
+Optional<IntPoint> ImageDecoder::hotSpot() const
{
RetainPtr<CFDictionaryRef> properties = adoptCF(CGImageSourceCopyPropertiesAtIndex(m_nativeDecoder.get(), 0, imageSourceOptions().get()));
if (!properties)
- return false;
+ return Nullopt;
int x = -1, y = -1;
CFNumberRef num = (CFNumberRef)CFDictionaryGetValue(properties.get(), CFSTR("hotspotX"));
if (!num || !CFNumberGetValue(num, kCFNumberIntType, &x))
- return false;
+ return Nullopt;
num = (CFNumberRef)CFDictionaryGetValue(properties.get(), CFSTR("hotspotY"));
if (!num || !CFNumberGetValue(num, kCFNumberIntType, &y))
- return false;
+ return Nullopt;
if (x < 0 || y < 0)
- return false;
+ return Nullopt;
- hotSpot = IntPoint(x, y);
- return true;
+ return IntPoint(x, y);
}
IntSize ImageDecoder::frameSizeAtIndex(size_t index, SubsamplingLevel subsamplingLevel) const
@@ -386,21 +376,21 @@
CGImageSourceUpdateData(m_nativeDecoder.get(), data, allDataReceived);
}
-void ImageDecoder::setData(SharedBuffer* data, bool allDataReceived)
+void ImageDecoder::setData(SharedBuffer& data, bool allDataReceived)
{
#if PLATFORM(COCOA)
// On Mac the NSData inside the SharedBuffer can be secretly appended to without the SharedBuffer's knowledge.
// We use SharedBuffer's ability to wrap itself inside CFData to get around this, ensuring that ImageIO is
// really looking at the SharedBuffer.
- setData(data->createCFData().get(), allDataReceived);
+ setData(data.createCFData().get(), allDataReceived);
#else
// Create a CGDataProvider to wrap the SharedBuffer.
- data->ref();
+ data.ref();
// We use the GetBytesAtPosition callback rather than the GetBytePointer one because SharedBuffer
// does not provide a way to lock down the byte pointer and guarantee that it won't move, which
// is a requirement for using the GetBytePointer callback.
CGDataProviderDirectCallbacks providerCallbacks = { 0, 0, 0, sharedBufferGetBytesAtPosition, sharedBufferRelease };
- RetainPtr<CGDataProviderRef> dataProvider = adoptCF(CGDataProviderCreateDirect(data, data->size(), &providerCallbacks));
+ RetainPtr<CGDataProviderRef> dataProvider = adoptCF(CGDataProviderCreateDirect(&data, data.size(), &providerCallbacks));
CGImageSourceUpdateDataProvider(m_nativeDecoder.get(), dataProvider.get(), allDataReceived);
#endif
}
Modified: trunk/Source/WebCore/platform/graphics/cg/ImageDecoderCG.h (199311 => 199312)
--- trunk/Source/WebCore/platform/graphics/cg/ImageDecoderCG.h 2016-04-11 21:32:30 UTC (rev 199311)
+++ trunk/Source/WebCore/platform/graphics/cg/ImageDecoderCG.h 2016-04-11 21:33:16 UTC (rev 199312)
@@ -29,19 +29,23 @@
#include "ImageSourceCG.h"
#include "IntSize.h"
+#include <wtf/Optional.h>
+
+typedef struct CGImageSource* CGImageSourceRef;
+typedef const struct __CFData* CFDataRef;
+
namespace WebCore {
class ImageDecoder {
public:
ImageDecoder();
- static std::unique_ptr<ImageDecoder> create()
+ static std::unique_ptr<ImageDecoder> create(const SharedBuffer&, ImageSource::AlphaOption, ImageSource::GammaAndColorProfileOption)
{
return std::make_unique<ImageDecoder>();
}
static size_t bytesDecodedToDetermineProperties();
- static SubsamplingLevel subsamplingLevelForScale(float scale, SubsamplingLevel maximumSubsamplingLevel);
String filenameExtension() const;
bool isSizeAvailable() const;
@@ -50,7 +54,7 @@
IntSize size() const;
size_t frameCount() const;
int repetitionCount() const;
- bool hotSpot(IntPoint& hotSpot) const;
+ Optional<IntPoint> hotSpot() const;
IntSize frameSizeAtIndex(size_t, SubsamplingLevel) const;
bool frameIsCompleteAtIndex(size_t) const;
@@ -64,8 +68,10 @@
NativeImagePtr createFrameImageAtIndex(size_t, SubsamplingLevel) const;
void setData(CFDataRef, bool allDataReceived);
- void setData(SharedBuffer*, bool allDataReceived);
+ void setData(SharedBuffer&, bool allDataReceived);
+ void clearFrameBufferCache(size_t) { }
+
protected:
mutable IntSize m_size;
RetainPtr<CGImageSourceRef> m_nativeDecoder;
Deleted: trunk/Source/WebCore/platform/graphics/cg/ImageSourceCG.cpp (199311 => 199312)
--- trunk/Source/WebCore/platform/graphics/cg/ImageSourceCG.cpp 2016-04-11 21:32:30 UTC (rev 199311)
+++ trunk/Source/WebCore/platform/graphics/cg/ImageSourceCG.cpp 2016-04-11 21:33:16 UTC (rev 199312)
@@ -1,215 +0,0 @@
-/*
- * Copyright (C) 2004, 2005, 2006, 2008, 2016 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. ``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
- * 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 "ImageSource.h"
-
-#if USE(CG)
-#include "ImageSourceCG.h"
-
-#include "ImageDecoderCG.h"
-#include "ImageOrientation.h"
-#include "SharedBuffer.h"
-
-namespace WebCore {
-
-ImageSource::ImageSource(ImageSource::AlphaOption, ImageSource::GammaAndColorProfileOption)
-{
- // FIXME: AlphaOption and GammaAndColorProfileOption are ignored.
-}
-
-ImageSource::~ImageSource()
-{
- clear(true);
-}
-
-void ImageSource::clear(bool destroyAllFrames, size_t, SharedBuffer* data, bool allDataReceived)
-{
- // Recent versions of ImageIO discard previously decoded image frames if the client
- // application no longer holds references to them, so there's no need to throw away
- // the decoder unless we're explicitly asked to destroy all of the frames.
- if (!destroyAllFrames)
- return;
-
- m_decoder = nullptr;
-
- if (data)
- setData(data, allDataReceived);
-}
-
-void ImageSource::ensureDecoderIsCreated(SharedBuffer*)
-{
- if (initialized())
- return;
- m_decoder = ImageDecoder::create();
-}
-
-void ImageSource::setData(SharedBuffer* data, bool allDataReceived)
-{
- if (!data)
- return;
-
- ensureDecoderIsCreated(data);
-
- if (!initialized()) {
- ASSERT_NOT_REACHED();
- return;
- }
-
- m_decoder->setData(data, allDataReceived);
-}
-
-String ImageSource::filenameExtension() const
-{
- return initialized() ? m_decoder->filenameExtension() : String();
-}
-
-SubsamplingLevel ImageSource::calculateMaximumSubsamplingLevel() const
-{
- if (!m_allowSubsampling || !allowSubsamplingOfFrameAtIndex(0))
- return 0;
-
- // Values chosen to be appropriate for iOS.
- const int cMaximumImageAreaBeforeSubsampling = 5 * 1024 * 1024;
- const SubsamplingLevel maxSubsamplingLevel = 3;
-
- SubsamplingLevel currentLevel = 0;
- for ( ; currentLevel <= maxSubsamplingLevel; ++currentLevel) {
- IntSize frameSize = frameSizeAtIndex(0, currentLevel);
- if (frameSize.area() < cMaximumImageAreaBeforeSubsampling)
- break;
- }
-
- return currentLevel;
-}
-
-SubsamplingLevel ImageSource::maximumSubsamplingLevel() const
-{
-#if PLATFORM(IOS)
- return calculateMaximumSubsamplingLevel();
-#endif
- return 0;
-}
-
-SubsamplingLevel ImageSource::subsamplingLevelForScale(float scale) const
-{
- return ImageDecoder::subsamplingLevelForScale(scale, maximumSubsamplingLevel());
-}
-
-bool ImageSource::isSizeAvailable()
-{
- return initialized() && m_decoder->isSizeAvailable();
-}
-
-bool ImageSource::allowSubsamplingOfFrameAtIndex(size_t index) const
-{
- return initialized() && m_decoder->allowSubsamplingOfFrameAtIndex(index);
-}
-
-IntSize ImageSource::frameSizeAtIndex(size_t index, SubsamplingLevel subsamplingLevel, RespectImageOrientationEnum shouldRespectImageOrientation) const
-{
- if (!initialized())
- return { };
-
- IntSize size = m_decoder->frameSizeAtIndex(index, subsamplingLevel);
- ImageOrientation orientation = m_decoder->orientationAtIndex(index);
-
- return shouldRespectImageOrientation == RespectImageOrientation && orientation.usesWidthAsHeight() ? size.transposedSize() : size;
-}
-
-ImageOrientation ImageSource::orientationAtIndex(size_t index) const
-{
- return initialized() ? m_decoder->orientationAtIndex(index) : ImageOrientation();
-}
-
-IntSize ImageSource::size() const
-{
- return frameSizeAtIndex(0, 0);
-}
-
-IntSize ImageSource::sizeRespectingOrientation() const
-{
- return frameSizeAtIndex(0, 0, RespectImageOrientation);
-}
-
-bool ImageSource::getHotSpot(IntPoint& hotSpot) const
-{
- return initialized() && m_decoder->hotSpot(hotSpot);
-}
-
-size_t ImageSource::bytesDecodedToDetermineProperties() const
-{
- return ImageDecoder::bytesDecodedToDetermineProperties();
-}
-
-int ImageSource::repetitionCount()
-{
- return initialized() ? m_decoder->repetitionCount() : cAnimationLoopOnce;
-}
-
-size_t ImageSource::frameCount() const
-{
- return initialized() ? m_decoder->frameCount() : 0;
-}
-
-RetainPtr<CGImageRef> ImageSource::createFrameImageAtIndex(size_t index, SubsamplingLevel subsamplingLevel)
-{
- return initialized() ? m_decoder->createFrameImageAtIndex(index, subsamplingLevel) : nullptr;
-}
-
-bool ImageSource::frameIsCompleteAtIndex(size_t index)
-{
- return initialized() && m_decoder->frameIsCompleteAtIndex(index);
-}
-
-float ImageSource::frameDurationAtIndex(size_t index)
-{
- return initialized() ? m_decoder->frameDurationAtIndex(index) : 0;
-}
-
-bool ImageSource::frameHasAlphaAtIndex(size_t index)
-{
- return !initialized() || m_decoder->frameHasAlphaAtIndex(index);
-}
-
-unsigned ImageSource::frameBytesAtIndex(size_t index, SubsamplingLevel subsamplingLevel) const
-{
- IntSize frameSize = frameSizeAtIndex(index, subsamplingLevel);
- return frameSize.area() * 4;
-}
-
-void ImageSource::dump(TextStream& ts) const
-{
- if (m_allowSubsampling)
- ts.dumpProperty("allow-subsampling", m_allowSubsampling);
-
- ImageOrientation orientation = orientationAtIndex(0);
- if (orientation != OriginTopLeft)
- ts.dumpProperty("orientation", orientation);
-}
-
-}
-
-#endif // USE(CG)
Modified: trunk/Source/WebCore/platform/image-decoders/ImageDecoder.cpp (199311 => 199312)
--- trunk/Source/WebCore/platform/image-decoders/ImageDecoder.cpp 2016-04-11 21:32:30 UTC (rev 199311)
+++ trunk/Source/WebCore/platform/image-decoders/ImageDecoder.cpp 2016-04-11 21:33:16 UTC (rev 199312)
@@ -1,4 +1,5 @@
/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
* Copyright (C) 2008-2009 Torch Mobile, Inc.
* Copyright (C) Research In Motion Limited 2009-2010. All rights reserved.
*
@@ -270,6 +271,12 @@
}
+bool ImageDecoder::frameIsCompleteAtIndex(size_t index)
+{
+ ImageFrame* buffer = frameBufferAtIndex(index);
+ return buffer && buffer->status() == ImageFrame::FrameComplete;
+}
+
bool ImageDecoder::frameHasAlphaAtIndex(size_t index) const
{
if (m_frameBufferCache.size() <= index)
@@ -287,6 +294,38 @@
return m_size.area() * sizeof(ImageFrame::PixelData);
}
+float ImageDecoder::frameDurationAtIndex(size_t index)
+{
+ ImageFrame* buffer = frameBufferAtIndex(index);
+ if (!buffer || buffer->status() == ImageFrame::FrameEmpty)
+ return 0;
+
+ // Many annoying ads specify a 0 duration to make an image flash as quickly as possible.
+ // We follow Firefox's behavior and use a duration of 100 ms for any frames that specify
+ // a duration of <= 10 ms. See <rdar://problem/7689300> and <http://webkit.org/b/36082>
+ // for more information.
+ const float duration = buffer->duration() / 1000.0f;
+ if (duration < 0.011f)
+ return 0.100f;
+ return duration;
+}
+
+NativeImagePtr ImageDecoder::createFrameImageAtIndex(size_t index, SubsamplingLevel)
+{
+ // Zero-height images can cause problems for some ports. If we have an
+ // empty image dimension, just bail.
+ if (size().isEmpty())
+ return nullptr;
+
+ ImageFrame* buffer = frameBufferAtIndex(index);
+ if (!buffer || buffer->status() == ImageFrame::FrameEmpty)
+ return nullptr;
+
+ // Return the buffer contents as a native image. For some ports, the data
+ // is already in a native container, and this just increments its refcount.
+ return buffer->asNewNativeImage();
+}
+
void ImageDecoder::prepareScaleDataIfNecessary()
{
m_scaled = false;
Modified: trunk/Source/WebCore/platform/image-decoders/ImageDecoder.h (199311 => 199312)
--- trunk/Source/WebCore/platform/image-decoders/ImageDecoder.h 2016-04-11 21:32:30 UTC (rev 199311)
+++ trunk/Source/WebCore/platform/image-decoders/ImageDecoder.h 2016-04-11 21:33:16 UTC (rev 199312)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2006 Apple Inc. All rights reserved.
+ * Copyright (C) 2006, 2016 Apple Inc. All rights reserved.
* Copyright (C) 2008-2009 Torch Mobile, Inc.
* Copyright (C) Research In Motion Limited 2009-2010. All rights reserved.
* Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies)
@@ -34,6 +34,7 @@
#include "PlatformScreen.h"
#include "SharedBuffer.h"
#include <wtf/Assertions.h>
+#include <wtf/Optional.h>
#include <wtf/RefPtr.h>
#include <wtf/Vector.h>
#include <wtf/text/WTFString.h>
@@ -235,15 +236,14 @@
WTF_MAKE_NONCOPYABLE(ImageDecoder); WTF_MAKE_FAST_ALLOCATED;
public:
ImageDecoder(ImageSource::AlphaOption alphaOption, ImageSource::GammaAndColorProfileOption gammaAndColorProfileOption)
- : m_scaled(false)
- , m_premultiplyAlpha(alphaOption == ImageSource::AlphaPremultiplied)
+ : m_premultiplyAlpha(alphaOption == ImageSource::AlphaPremultiplied)
, m_ignoreGammaAndColorProfile(gammaAndColorProfileOption == ImageSource::GammaAndColorProfileIgnored)
- , m_sizeAvailable(false)
- , m_maxNumPixels(-1)
- , m_isAllDataReceived(false)
- , m_failed(false) { }
+ {
+ }
- virtual ~ImageDecoder() { }
+ virtual ~ImageDecoder()
+ {
+ }
// Returns a caller-owned decoder of the appropriate type. Returns 0 if
// we can't sniff a supported type from the provided data (possibly
@@ -254,11 +254,11 @@
bool isAllDataReceived() const { return m_isAllDataReceived; }
- virtual void setData(SharedBuffer* data, bool allDataReceived)
+ virtual void setData(SharedBuffer& data, bool allDataReceived)
{
if (m_failed)
return;
- m_data = data;
+ m_data = &data;
m_isAllDataReceived = allDataReceived;
}
@@ -282,7 +282,7 @@
// sizes. This does NOT differ from size() for GIF, since decoding GIFs
// composites any smaller frames against previous frames to create full-
// size frames.
- virtual IntSize frameSizeAtIndex(size_t) const
+ virtual IntSize frameSizeAtIndex(size_t, SubsamplingLevel) const
{
return size();
}
@@ -310,16 +310,24 @@
// ImageDecoder-owned pointer.
virtual ImageFrame* frameBufferAtIndex(size_t) = 0;
+ bool frameIsCompleteAtIndex(size_t);
+
// Make the best effort guess to check if the requested frame has alpha channel.
- virtual bool frameHasAlphaAtIndex(size_t) const;
+ bool frameHasAlphaAtIndex(size_t) const;
// Number of bytes in the decoded frame requested. Return 0 if not yet decoded.
- virtual unsigned frameBytesAtIndex(size_t) const;
+ unsigned frameBytesAtIndex(size_t) const;
+
+ float frameDurationAtIndex(size_t);
+
+ NativeImagePtr createFrameImageAtIndex(size_t, SubsamplingLevel);
void setIgnoreGammaAndColorProfile(bool flag) { m_ignoreGammaAndColorProfile = flag; }
bool ignoresGammaAndColorProfile() const { return m_ignoreGammaAndColorProfile; }
- ImageOrientation orientation() const { return m_orientation; }
+ ImageOrientation orientationAtIndex(size_t) const { return m_orientation; }
+
+ bool allowSubsamplingOfFrameAtIndex(size_t) const { return false; }
enum { iccColorProfileHeaderLength = 128 };
@@ -330,6 +338,10 @@
return !memcmp(&profileData[16], "RGB ", 4);
}
+ static size_t bytesDecodedToDetermineProperties() { return 0; }
+
+ static SubsamplingLevel subsamplingLevelForScale(float, SubsamplingLevel) { return 0; }
+
static bool inputDeviceColorProfile(const char* profileData, unsigned profileLength)
{
ASSERT_UNUSED(profileLength, profileLength >= iccColorProfileHeaderLength);
@@ -354,13 +366,9 @@
// compositing).
virtual void clearFrameBufferCache(size_t) { }
-#if ENABLE(IMAGE_DECODER_DOWN_SAMPLING)
- void setMaxNumPixels(int m) { m_maxNumPixels = m; }
-#endif
-
// If the image has a cursor hot-spot, stores it in the argument
// and returns true. Otherwise returns false.
- virtual bool hotSpot(IntPoint&) const { return false; }
+ virtual Optional<IntPoint> hotSpot() const { return Nullopt; }
protected:
void prepareScaleDataIfNecessary();
@@ -374,7 +382,7 @@
Vector<ImageFrame, 1> m_frameBufferCache;
// FIXME: Do we need m_colorProfile any more, for any port?
ColorProfile m_colorProfile;
- bool m_scaled;
+ bool m_scaled { false };
Vector<int> m_scaledColumns;
Vector<int> m_scaledRows;
bool m_premultiplyAlpha;
@@ -392,10 +400,14 @@
}
IntSize m_size;
- bool m_sizeAvailable;
- int m_maxNumPixels;
- bool m_isAllDataReceived;
- bool m_failed;
+ bool m_sizeAvailable { false };
+#if ENABLE(IMAGE_DECODER_DOWN_SAMPLING)
+ static const int m_maxNumPixels { 1024 * 1024 };
+#else
+ static const int m_maxNumPixels { -1 };
+#endif
+ bool m_isAllDataReceived { false };
+ bool m_failed { false };
};
} // namespace WebCore
Modified: trunk/Source/WebCore/platform/image-decoders/bmp/BMPImageDecoder.cpp (199311 => 199312)
--- trunk/Source/WebCore/platform/image-decoders/bmp/BMPImageDecoder.cpp 2016-04-11 21:32:30 UTC (rev 199311)
+++ trunk/Source/WebCore/platform/image-decoders/bmp/BMPImageDecoder.cpp 2016-04-11 21:33:16 UTC (rev 199312)
@@ -47,14 +47,14 @@
{
}
-void BMPImageDecoder::setData(SharedBuffer* data, bool allDataReceived)
+void BMPImageDecoder::setData(SharedBuffer& data, bool allDataReceived)
{
if (failed())
return;
ImageDecoder::setData(data, allDataReceived);
if (m_reader)
- m_reader->setData(data);
+ m_reader->setData(&data);
}
bool BMPImageDecoder::isSizeAvailable()
Modified: trunk/Source/WebCore/platform/image-decoders/bmp/BMPImageDecoder.h (199311 => 199312)
--- trunk/Source/WebCore/platform/image-decoders/bmp/BMPImageDecoder.h 2016-04-11 21:32:30 UTC (rev 199311)
+++ trunk/Source/WebCore/platform/image-decoders/bmp/BMPImageDecoder.h 2016-04-11 21:33:16 UTC (rev 199312)
@@ -42,7 +42,7 @@
// ImageDecoder
virtual String filenameExtension() const { return "bmp"; }
- virtual void setData(SharedBuffer*, bool allDataReceived);
+ virtual void setData(SharedBuffer&, bool allDataReceived);
virtual bool isSizeAvailable();
virtual ImageFrame* frameBufferAtIndex(size_t index);
// CAUTION: setFailed() deletes |m_reader|. Be careful to avoid
Modified: trunk/Source/WebCore/platform/image-decoders/gif/GIFImageDecoder.cpp (199311 => 199312)
--- trunk/Source/WebCore/platform/image-decoders/gif/GIFImageDecoder.cpp 2016-04-11 21:32:30 UTC (rev 199311)
+++ trunk/Source/WebCore/platform/image-decoders/gif/GIFImageDecoder.cpp 2016-04-11 21:33:16 UTC (rev 199312)
@@ -42,14 +42,14 @@
{
}
-void GIFImageDecoder::setData(SharedBuffer* data, bool allDataReceived)
+void GIFImageDecoder::setData(SharedBuffer& data, bool allDataReceived)
{
if (failed())
return;
ImageDecoder::setData(data, allDataReceived);
if (m_reader)
- m_reader->setData(data);
+ m_reader->setData(&data);
}
bool GIFImageDecoder::isSizeAvailable()
@@ -303,7 +303,7 @@
if (!m_reader) {
m_reader = std::make_unique<GIFImageReader>(this);
- m_reader->setData(m_data);
+ m_reader->setData(m_data.get());
}
if (query == GIFSizeQuery) {
Modified: trunk/Source/WebCore/platform/image-decoders/gif/GIFImageDecoder.h (199311 => 199312)
--- trunk/Source/WebCore/platform/image-decoders/gif/GIFImageDecoder.h 2016-04-11 21:32:30 UTC (rev 199311)
+++ trunk/Source/WebCore/platform/image-decoders/gif/GIFImageDecoder.h 2016-04-11 21:33:16 UTC (rev 199312)
@@ -42,7 +42,7 @@
// ImageDecoder
virtual String filenameExtension() const { return "gif"; }
- virtual void setData(SharedBuffer* data, bool allDataReceived);
+ virtual void setData(SharedBuffer& data, bool allDataReceived);
virtual bool isSizeAvailable();
virtual bool setSize(unsigned width, unsigned height);
virtual size_t frameCount();
Modified: trunk/Source/WebCore/platform/image-decoders/gif/GIFImageReader.h (199311 => 199312)
--- trunk/Source/WebCore/platform/image-decoders/gif/GIFImageReader.h 2016-04-11 21:32:30 UTC (rev 199311)
+++ trunk/Source/WebCore/platform/image-decoders/gif/GIFImageReader.h 2016-04-11 21:33:16 UTC (rev 199312)
@@ -246,7 +246,7 @@
{
}
- void setData(PassRefPtr<WebCore::SharedBuffer> data) { m_data = data; }
+ void setData(WebCore::SharedBuffer* data) { m_data = data; }
// FIXME: haltAtFrame should be size_t.
bool decode(WebCore::GIFImageDecoder::GIFQuery, unsigned haltAtFrame);
Modified: trunk/Source/WebCore/platform/image-decoders/ico/ICOImageDecoder.cpp (199311 => 199312)
--- trunk/Source/WebCore/platform/image-decoders/ico/ICOImageDecoder.cpp 2016-04-11 21:32:30 UTC (rev 199311)
+++ trunk/Source/WebCore/platform/image-decoders/ico/ICOImageDecoder.cpp 2016-04-11 21:33:16 UTC (rev 199312)
@@ -55,7 +55,7 @@
{
}
-void ICOImageDecoder::setData(SharedBuffer* data, bool allDataReceived)
+void ICOImageDecoder::setData(SharedBuffer& data, bool allDataReceived)
{
if (failed())
return;
@@ -64,7 +64,7 @@
for (BMPReaders::iterator i(m_bmpReaders.begin()); i != m_bmpReaders.end(); ++i) {
if (*i)
- (*i)->setData(data);
+ (*i)->setData(&data);
}
for (size_t i = 0; i < m_pngDecoders.size(); ++i)
setDataForPNGDecoderAtIndex(i);
@@ -128,21 +128,20 @@
return ImageDecoder::setFailed();
}
-bool ICOImageDecoder::hotSpot(IntPoint& hotSpot) const
+Optional<IntPoint> ICOImageDecoder::hotSpot() const
{
// When unspecified, the default frame is always frame 0. This is consistent with
// BitmapImage where currentFrame() starts at 0 and only increases when animation is
// requested.
- return hotSpotAtIndex(0, hotSpot);
+ return hotSpotAtIndex(0);
}
-bool ICOImageDecoder::hotSpotAtIndex(size_t index, IntPoint& hotSpot) const
+Optional<IntPoint> ICOImageDecoder::hotSpotAtIndex(size_t index) const
{
if (index >= m_dirEntries.size() || m_fileType != CURSOR)
- return false;
+ return Nullopt;
- hotSpot = m_dirEntries[index].m_hotSpot;
- return true;
+ return m_dirEntries[index].m_hotSpot;
}
@@ -165,7 +164,7 @@
// FIXME: Save this copy by making the PNG decoder able to take an
// optional offset.
RefPtr<SharedBuffer> pngData(SharedBuffer::create(&m_data->data()[dirEntry.m_imageOffset], m_data->size() - dirEntry.m_imageOffset));
- m_pngDecoders[index]->setData(pngData.get(), isAllDataReceived());
+ m_pngDecoders[index]->setData(*pngData, isAllDataReceived());
}
void ICOImageDecoder::decode(size_t index, bool onlySize)
Modified: trunk/Source/WebCore/platform/image-decoders/ico/ICOImageDecoder.h (199311 => 199312)
--- trunk/Source/WebCore/platform/image-decoders/ico/ICOImageDecoder.h 2016-04-11 21:32:30 UTC (rev 199311)
+++ trunk/Source/WebCore/platform/image-decoders/ico/ICOImageDecoder.h 2016-04-11 21:33:16 UTC (rev 199312)
@@ -45,7 +45,7 @@
// ImageDecoder
virtual String filenameExtension() const { return "ico"; }
- virtual void setData(SharedBuffer*, bool allDataReceived);
+ virtual void setData(SharedBuffer&, bool allDataReceived);
virtual bool isSizeAvailable();
virtual IntSize size() const;
virtual IntSize frameSizeAtIndex(size_t) const;
@@ -56,7 +56,7 @@
// avoid accessing deleted memory, especially when calling this from
// inside BMPImageReader!
virtual bool setFailed();
- virtual bool hotSpot(IntPoint&) const;
+ virtual Optional<IntPoint> hotSpot() const;
private:
enum ImageType {
@@ -116,9 +116,8 @@
// could be decoded.
bool processDirectoryEntries();
- // Stores the hot-spot for |index| in |hotSpot| and returns true,
- // or returns false if there is none.
- bool hotSpotAtIndex(size_t index, IntPoint& hotSpot) const;
+ // Returns the hot-spot for |index|, returns Nullopt if there is none.
+ Optional<IntPoint> hotSpotAtIndex(size_t) const;
// Reads and returns a directory entry from the current offset into
// |data|.
Modified: trunk/Source/WebKit2/ChangeLog (199311 => 199312)
--- trunk/Source/WebKit2/ChangeLog 2016-04-11 21:32:30 UTC (rev 199311)
+++ trunk/Source/WebKit2/ChangeLog 2016-04-11 21:33:16 UTC (rev 199312)
@@ -1,3 +1,14 @@
+2016-04-11 Said Abou-Hallawa <sabouhallawa@apple,com>
+
+ Merge CG ImageSource and non CG ImageSource implementation in one file
+ https://bugs.webkit.org/show_bug.cgi?id=155456
+
+ Reviewed by Darin Adler.
+
+ * UIProcess/API/efl/EwkView.cpp:
+ (EwkView::setCursor):
+ Replace the call to Image::getHotSpot() by Image::hotSpot().
+
2016-04-11 Anders Carlsson <[email protected]>
Rename WKOpenPanelParameters files to WKOpenPanelParametersRef
Modified: trunk/Source/WebKit2/UIProcess/API/efl/EwkView.cpp (199311 => 199312)
--- trunk/Source/WebKit2/UIProcess/API/efl/EwkView.cpp 2016-04-11 21:32:30 UTC (rev 199311)
+++ trunk/Source/WebKit2/UIProcess/API/efl/EwkView.cpp 2016-04-11 21:33:16 UTC (rev 199312)
@@ -450,10 +450,9 @@
if (cursorImage == m_cursorIdentifier.image)
return;
- IntPoint hotSpot;
- cursorImage->getHotSpot(hotSpot);
-
- Ecore_X_Cursor customCursor = createCustomCursor(window, cursorImage, IntSize(cursorImage->size()), hotSpot);
+
+ Optional<IntPoint> hotSpot = cursorImage->hotSpot();
+ Ecore_X_Cursor customCursor = createCustomCursor(window, cursorImage, IntSize(cursorImage->size()), hotSpot ? hotSpot.value() : IntPoint());
if (!customCursor)
return;