Source/WebCore/ChangeLog

 12016-07-12 Said Abou-Hallawa <sabouhallawa@apple.com>
 2
 3 Split the pixel data of ImageFrame to a separate class
 4 https://bugs.webkit.org/show_bug.cgi?id=159679
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 Move the pixel data manipulation part in ImageFrame into a separate class
 9 and then make it optional (allocated on demand).
 10
 11 * CMakeLists.txt:
 12 * PlatformEfl.cmake:
 13 * PlatformGTK.cmake:
 14 * PlatformWinCairo.cmake:
 15 * WebCore.xcodeproj/project.pbxproj:
 16 * platform/graphics/BitmapPixels.h: Added.
 17 (WebCore::BitmapPixels::create):
 18 (WebCore::BitmapPixels::BitmapPixels):
 19 (WebCore::BitmapPixels::width):
 20 (WebCore::BitmapPixels::height):
 21 (WebCore::BitmapPixels::setSize):
 22 (WebCore::BitmapPixels::at):
 23 (WebCore::BitmapPixels::clear):
 24 (WebCore::BitmapPixels::clearRect):
 25 (WebCore::BitmapPixels::repeatFirstRow):
 26 (WebCore::BitmapPixels::setRGBA):
 27 (WebCore::BitmapPixels::overRGBA):
 28 (WebCore::BitmapPixels::inBounds):
 29 * platform/graphics/Color.cpp:
 30 (WebCore::multiply255):
 31 (WebCore::divide255):
 32 (WebCore::divideCeil):
 33 (WebCore::premultipliedChannel):
 34 (WebCore::unpremultipliedChannel):
 35 (WebCore::makePremultipliedRGBA):
 36 (WebCore::makeUnPremultipliedRGBA):
 37 * platform/graphics/Color.h:
 38 * platform/graphics/ImageFrameData.h:
 39 (WebCore::ImageFrameData::pixels):
 40 (WebCore::ImageFrameData::hasPixels):
 41 * platform/image-decoders/ImageDecoder.cpp:
 42 (WebCore::ImageFrame::operator=):
 43 (WebCore::ImageFrame::clearPixelData):
 44 (WebCore::ImageFrame::zeroFillPixelData):
 45 (WebCore::ImageFrame::zeroFillFrameRect):
 46 (WebCore::ImageFrame::copyBitmapData):
 47 (WebCore::ImageFrame::setSize):
 48 (WebCore::ImageFrame::copyRowNTimes):
 49 * platform/image-decoders/ImageDecoder.h:
 50 (WebCore::ImageFrame::asNewNativeImage):
 51 (WebCore::ImageFrame::setRGBA):
 52 (WebCore::ImageFrame::getAddr):
 53 (WebCore::ImageFrame::hasPixelData):
 54 (WebCore::ImageFrame::overRGBA):
 55 (WebCore::ImageFrame::width):
 56 (WebCore::ImageFrame::height):
 57 (WebCore::ImageFrame::copyRowNTimes): Deleted.
 58 (WebCore::ImageFrame::fixPointUnsignedMultiply): Deleted.
 59 (WebCore::ImageFrame::divide255): Deleted.
 60 * platform/image-decoders/bmp/BMPImageReader.cpp:
 61 (WebCore::BMPImageReader::decodeBMP):
 62 * platform/image-decoders/cairo/BitmapPixelsCairo.cpp: Renamed from Source/WebCore/platform/image-decoders/cairo/ImageDecoderCairo.cpp.
 63 (WebCore::BitmapPixels::image):
 64 * platform/image-decoders/gif/GIFImageDecoder.cpp:
 65 (WebCore::GIFImageDecoder::haveDecodedRow):
 66 (WebCore::GIFImageDecoder::frameComplete):
 67 (WebCore::GIFImageDecoder::initFrameBuffer):
 68 * platform/image-decoders/jpeg/JPEGImageDecoder.cpp:
 69 (WebCore::setPixel):
 70 (WebCore::JPEGImageDecoder::outputScanlines):
 71 * platform/image-decoders/png/PNGImageDecoder.cpp:
 72 (WebCore::setPixelRGB):
 73 (WebCore::setPixelRGBA):
 74 (WebCore::setPixelPremultipliedRGBA):
 75 (WebCore::PNGImageDecoder::rowAvailable):
 76 (WebCore::PNGImageDecoder::initFrameBuffer):
 77 (WebCore::PNGImageDecoder::frameComplete):
 78 * platform/image-decoders/webp/WEBPImageDecoder.cpp:
 79 (WebCore::WEBPImageDecoder::decode):
 80
 812016-07-11 Said Abou-Hallawa <sabouhallawa@apple,com>
 82
 83 Rename FrameData to ImageFrameData and move it to a separate file
 84 https://bugs.webkit.org/show_bug.cgi?id=155444
 85
 86 Reviewed by NOBODY (OOPS!).
 87
 88 Move ImageFrameData to a separate file so it can be cached by ImageSource
 89 and will still be consumed by BitmapImage. Make the data members of ImageFrameData
 90 be private and add getters to return their values.
 91
 92 No new tests -- Code refactoring, no behavior change.
 93
 94 * CMakeLists.txt:
 95 * WebCore.xcodeproj/project.pbxproj:
 96 * platform/graphics/BitmapImage.cpp:
 97 (WebCore::BitmapImage::BitmapImage):
 98 (WebCore::BitmapImage::haveFrameImageAtIndex):
 99 (WebCore::BitmapImage::destroyDecodedData):
 100 (WebCore::BitmapImage::destroyDecodedDataIfNecessary):
 101 (WebCore::BitmapImage::cacheFrame):
 102 (WebCore::BitmapImage::dataChanged):
 103 (WebCore::BitmapImage::ensureFrameIsCached):
 104 (WebCore::BitmapImage::frameImageAtIndex):
 105 (WebCore::BitmapImage::frameIsCompleteAtIndex):
 106 (WebCore::BitmapImage::frameDurationAtIndex):
 107 (WebCore::BitmapImage::frameHasAlphaAtIndex):
 108 (WebCore::BitmapImage::frameOrientationAtIndex):
 109 (WebCore::BitmapImage::singlePixelSolidColor):
 110 (WebCore::BitmapImage::isAlmostSolidColor):
 111 * platform/graphics/BitmapImage.h:
 112 (WebCore::FrameData::FrameData): Deleted.
 113 (WebCore::FrameData::~FrameData): Deleted.
 114 (WebCore::FrameData::usedFrameBytes): Deleted.
 115 * platform/graphics/ImageSource.cpp:
 116 (WebCore::ImageSource::createFrameDataAtIndex):
 117 * platform/graphics/ImageSource.h:
 118 * platform/graphics/imageFrameData.cpp: Added.
 119 (WebCore::ImageFrameData::ImageFrameData):
 120 (WebCore::ImageFrameData::~ImageFrameData):
 121 (WebCore::ImageFrameData::clearSubImages):
 122 (WebCore::ImageFrameData::clear):
 123 (WebCore::ImageFrameData::singlePixelSolidColor):
 124 (WebCore::ImageFrameData::isAlmostSolidColor):
 125 * platform/graphics/imageFrameData.h: Added.
 126 (WebCore::ImageFrameData::status):
 127 (WebCore::ImageFrameData::isComplete):
 128 (WebCore::ImageFrameData::size):
 129 (WebCore::ImageFrameData::frameBytes):
 130 (WebCore::ImageFrameData::image):
 131 (WebCore::ImageFrameData::orientation):
 132 (WebCore::ImageFrameData::subsamplingLevel):
 133 (WebCore::ImageFrameData::duration):
 134 (WebCore::ImageFrameData::hasAlpha):
 135 (WebCore::ImageFrameData::hasImage):
 136 (WebCore::ImageFrameData::hasMetadata):
 137
 1382016-06-24 Said Abou-Hallawa <sabouhallawa@apple,com>
 139
 140 Introduce PlatformImage and make it is a wrapper for NativeImagePtr
 141 https://bugs.webkit.org/show_bug.cgi?id=158684
 142
 143 Reviewed by NOBODY (OOPS!).
 144
 145 The main purpose of this refactoring is to move the platform image dependent
 146 code from BitmapImage to PlatformImage. PlatformImage is responsible of
 147 drawing the image and answering NativeImagePtr questions when an ImageDecoder
 148 is not available. Apart from drawing the image, the query functions will be
 149 called only when constructing a FrameData so we will keep everything as a
 150 NativeImagePtr. But we will cast the NativeImagePtr to PlatformImage when
 151 a platform dependent function is needed.
 152
 153 No new tests -- Code refactoring, no behavior change.
 154
 155 * PlatformAppleWin.cmake:
 156 * PlatformEfl.cmake:
 157 * PlatformGTK.cmake:
 158 * PlatformMac.cmake:
 159 * PlatformWinCairo.cmake:
 160 * WebCore.xcodeproj/project.pbxproj:
 161 * bindings/objc/DOM.mm:
 162 (-[DOMNode getPreviewSnapshotImage:andRects:]):
 163 * page/mac/TextIndicatorWindow.mm:
 164 (-[WebTextIndicatorView initWithFrame:textIndicator:margin:offset:]):
 165 (createContentCrossfadeAnimation):
 166 * platform/graphics/BitmapImage.cpp:
 167 (WebCore::BitmapImage::BitmapImage):
 168 (WebCore::BitmapImage::destroyDecodedData):
 169 (WebCore::BitmapImage::destroyDecodedDataIfNecessary):
 170 (WebCore::BitmapImage::dataChanged):
 171 (WebCore::BitmapImage::frameImageAtIndex):
 172 (WebCore::BitmapImage::nativeImage):
 173 (WebCore::BitmapImage::nativeImageOfSize):
 174 (WebCore::BitmapImage::nativeImageForCurrentFrame):
 175 (WebCore::BitmapImage::framesNativeImages):
 176 (WebCore::BitmapImage::singlePixelSolidColor):
 177 (WebCore::BitmapImage::isAlmostSolidColor):
 178 (WebCore::BitmapImage::draw):
 179 * platform/graphics/BitmapImage.h:
 180 (WebCore::FrameData::FrameData):
 181 m_hasAlpha can be initialized with false because it is accessed only in
 182 BitmapImage::frameHasAlphaAtIndex() and it is guarded by m_haveMetadata.
 183 Both m_haveMetadata and m_hasAlpha are set in BitmapImage constructor
 184 and in BitmapImage::cacheFrame().
 185
 186 (WebCore::FrameData::~FrameData):
 187 (WebCore::FrameData::clear):
 188 * platform/graphics/Image.h:
 189 (WebCore::Image::nativeImage):
 190 (WebCore::Image::nativeImageOfSize):
 191 (WebCore::Image::framesNativeImages):
 192 (WebCore::Image::getCGImageRef): Deleted.
 193 (WebCore::Image::getFirstCGImageRefOfSize): Deleted.
 194 (WebCore::Image::getCGImageArray): Deleted.
 195 * platform/graphics/PlatformImage.h: Added.
 196 (WebCore::PlatformImage::PlatformImage):
 197 (WebCore::PlatformImage::isNil):
 198 (WebCore::PlatformImage::cgImageRef):
 199 * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.mm:
 200 (WebCore::MediaPlayerPrivateMediaStreamAVFObjC::updateDisplayMode):
 201 * platform/graphics/cairo/PlatformImageCairo.cpp: Renamed from Source/WebCore/platform/graphics/cairo/BitmapImageCairo.cpp.
 202 (WebCore::PlatformImage::clearSubImages):
 203 (WebCore::PlatformImage::size):
 204 (WebCore::PlatformImage::hasAlpha):
 205 (WebCore::PlatformImage::singlePixelSolidColor):
 206 (WebCore::PlatformImage::isAlmostSolidColor):
 207 (WebCore::PlatformImage::subsamplingScale):
 208 (WebCore::PlatformImage::draw):
 209 * platform/graphics/cg/BitmapImageCG.cpp: Removed.
 210 * platform/graphics/cg/PatternCG.cpp:
 211 (WebCore::Pattern::createPlatformPattern):
 212 * platform/graphics/cg/PlatformImageCG.cpp: Added.
 213 (WebCore::PlatformImage::clearSubImages):
 214 (WebCore::PlatformImage::size):
 215 (WebCore::PlatformImage::hasAlpha):
 216 (WebCore::PlatformImage::singlePixelSolidColor):
 217 (WebCore::PlatformImage::isAlmostSolidColor): Moved from PluginView.cpp since PlatformImage is what this function belongs to.
 218 (WebCore::PlatformImage::subsamplingScale): Returns the sub-sampling scale based on the context scaling.
 219 (WebCore::PlatformImage::draw):
 220 * platform/graphics/cocoa/TextTrackRepresentationCocoa.mm:
 221 (TextTrackRepresentationCocoa::update):
 222 * platform/graphics/mac/ImageMac.mm:
 223 (WebCore::BitmapImage::getTIFFRepresentation):
 224 * platform/mediastream/mac/MockRealtimeVideoSourceMac.mm:
 225 (WebCore::MockRealtimeVideoSourceMac::updatePlatformLayer):
 226 * platform/win/DragImageCGWin.cpp:
 227 (WebCore::createDragImageFromImage):
 228
12292016-07-11 Sam Weinig <sam@webkit.org>
2230
3231 Speech Synthesis: getting list of voices no longer works

Source/WebKit/mac/ChangeLog

 12016-07-11 Said Abou-Hallawa <sabouhallawa@apple,com>
 2
 3 Introduce PlatformImage and make it is a wrapper for NativeImagePtr
 4 https://bugs.webkit.org/show_bug.cgi?id=158684
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 * Misc/WebCache.mm:
 9 (+[WebCache imageForURL:]):
 10
1112016-07-11 Enrica Casucci <enrica@apple.com>
212
313 Add synthetic click origin to WKNavigationAction.

Source/WebKit2/ChangeLog

 12016-07-11 Said Abou-Hallawa <sabouhallawa@apple,com>
 2
 3 Introduce PlatformImage and make it is a wrapper for NativeImagePtr
 4 https://bugs.webkit.org/show_bug.cgi?id=158684
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 * UIProcess/API/C/cg/WKIconDatabaseCG.cpp:
 9 (WKIconDatabaseTryGetCGImageForURL):
 10 (WKIconDatabaseTryCopyCGImageArrayForURL):
 11 It was the only place in the code which uses BitmapImage::getCGImageArray().
 12 Call BitmapImage::framesNativeImages() instead and form the returned
 13 Vector<NativeImagePtr> build the CFArrayRef.
 14
 15 * UIProcess/ios/WKContentViewInteraction.mm:
 16 (-[WKContentView _presentationSnapshotForPreviewItemController:]):
 17 * WebProcess/Plugins/PluginView.cpp:
 18 (WebKit::PluginView::pluginSnapshotTimerFired):
 19
 20 (WebKit::isAlmostSolidColor): Deleted.
 21 Move the static function isAlmostSolidColor to PlatformImage::isAlmostSolidColor().
 22
1232016-07-11 Chris Dumez <cdumez@apple.com>
224
325 [WK2][iOS] Intermittent crash in [UIApplication beginBackgroundTaskWithName] expiration handler

Source/WebCore/CMakeLists.txt

@@set(WebCore_SOURCES
22262226 platform/graphics/ISOVTTCue.cpp
22272227 platform/graphics/Image.cpp
22282228 platform/graphics/ImageBuffer.cpp
 2229 platform/graphics/ImageFrameData.cpp
22292230 platform/graphics/ImageOrientation.cpp
22302231 platform/graphics/ImageSource.cpp
22312232 platform/graphics/IntPoint.cpp

Source/WebCore/PlatformAppleWin.cmake

@@list(APPEND WebCore_SOURCES
5555 platform/graphics/ca/win/WebTiledBackingLayerWin.cpp
5656 platform/graphics/ca/win/WKCACFViewLayerTreeHost.cpp
5757
58  platform/graphics/cg/BitmapImageCG.cpp
5958 platform/graphics/cg/ColorCG.cpp
6059 platform/graphics/cg/FloatPointCG.cpp
6160 platform/graphics/cg/FloatRectCG.cpp

@@list(APPEND WebCore_SOURCES
7574 platform/graphics/cg/PDFDocumentImage.cpp
7675 platform/graphics/cg/PathCG.cpp
7776 platform/graphics/cg/PatternCG.cpp
 77 platform/graphics/cg/PlatformImageCG.cpp
7878 platform/graphics/cg/SubimageCacheWithTimer.cpp
7979 platform/graphics/cg/TransformationMatrixCG.cpp
8080

Source/WebCore/PlatformEfl.cmake

@@list(APPEND WebCore_SOURCES
122122 platform/graphics/PlatformDisplay.cpp
123123
124124 platform/graphics/cairo/BackingStoreBackendCairoImpl.cpp
125  platform/graphics/cairo/BitmapImageCairo.cpp
126125 platform/graphics/cairo/CairoUtilities.cpp
127126 platform/graphics/cairo/FontCairo.cpp
128127 platform/graphics/cairo/FontCairoHarfbuzzNG.cpp

@@list(APPEND WebCore_SOURCES
134133 platform/graphics/cairo/PathCairo.cpp
135134 platform/graphics/cairo/PatternCairo.cpp
136135 platform/graphics/cairo/PlatformContextCairo.cpp
 136 platform/graphics/cairo/PlatformImageCairo.cpp
137137 platform/graphics/cairo/PlatformPathCairo.cpp
138138 platform/graphics/cairo/RefPtrCairo.cpp
139139 platform/graphics/cairo/TransformationMatrixCairo.cpp

@@list(APPEND WebCore_SOURCES
179179 platform/graphics/x11/PlatformDisplayX11.cpp
180180 platform/graphics/x11/XUniqueResource.cpp
181181
182  platform/image-encoders/JPEGImageEncoder.cpp
 182 platform/image-decoders/cairo/BitmapPixelsCairo.cpp
183183
184  platform/image-decoders/cairo/ImageDecoderCairo.cpp
 184 platform/image-encoders/JPEGImageEncoder.cpp
185185
186186 platform/network/efl/NetworkStateNotifierEfl.cpp
187187

Source/WebCore/PlatformGTK.cmake

@@list(APPEND WebCore_SOURCES
101101
102102 platform/graphics/cairo/BackingStoreBackendCairoImpl.cpp
103103 platform/graphics/cairo/BackingStoreBackendCairoX11.cpp
104  platform/graphics/cairo/BitmapImageCairo.cpp
105104 platform/graphics/cairo/CairoUtilities.cpp
106105 platform/graphics/cairo/FloatRectCairo.cpp
107106 platform/graphics/cairo/FontCairo.cpp

@@list(APPEND WebCore_SOURCES
115114 platform/graphics/cairo/PathCairo.cpp
116115 platform/graphics/cairo/PatternCairo.cpp
117116 platform/graphics/cairo/PlatformContextCairo.cpp
 117 platform/graphics/cairo/PlatformImageCairo.cpp
118118 platform/graphics/cairo/PlatformPathCairo.cpp
119119 platform/graphics/cairo/RefPtrCairo.cpp
120120 platform/graphics/cairo/TransformationMatrixCairo.cpp

@@list(APPEND WebCore_SOURCES
149149 platform/gtk/TemporaryLinkStubs.cpp
150150 platform/gtk/UserAgentGtk.cpp
151151
152  platform/image-decoders/cairo/ImageDecoderCairo.cpp
 152 platform/image-decoders/cairo/BitmapPixelsCairo.cpp
153153
154154 platform/mediastream/gtk/SDPProcessorScriptResourceGtk.cpp
155155

Source/WebCore/PlatformMac.cmake

@@list(APPEND WebCore_SOURCES
397397 platform/graphics/ca/cocoa/WebSystemBackdropLayer.mm
398398 platform/graphics/ca/cocoa/WebTiledBackingLayer.mm
399399
400  platform/graphics/cg/BitmapImageCG.cpp
401400 platform/graphics/cg/ColorCG.cpp
402401 platform/graphics/cg/FloatPointCG.cpp
403402 platform/graphics/cg/FloatRectCG.cpp

@@list(APPEND WebCore_SOURCES
417416 platform/graphics/cg/PDFDocumentImage.cpp
418417 platform/graphics/cg/PathCG.cpp
419418 platform/graphics/cg/PatternCG.cpp
 419 platform/graphics/cg/PlatformImageCG.cpp
420420 platform/graphics/cg/SubimageCacheWithTimer.cpp
421421 platform/graphics/cg/TransformationMatrixCG.cpp
422422

Source/WebCore/PlatformWinCairo.cmake

@@list(APPEND WebCore_SOURCES
2121 platform/graphics/GLContext.cpp
2222 platform/graphics/PlatformDisplay.cpp
2323
24  platform/graphics/cairo/BitmapImageCairo.cpp
2524 platform/graphics/cairo/CairoUtilities.cpp
2625 platform/graphics/cairo/FloatRectCairo.cpp
2726 platform/graphics/cairo/FontCairo.cpp

@@list(APPEND WebCore_SOURCES
3433 platform/graphics/cairo/PathCairo.cpp
3534 platform/graphics/cairo/PatternCairo.cpp
3635 platform/graphics/cairo/PlatformContextCairo.cpp
 36 platform/graphics/cairo/PlatformImageCairo.cpp
3737 platform/graphics/cairo/PlatformPathCairo.cpp
3838 platform/graphics/cairo/RefPtrCairo.cpp
3939 platform/graphics/cairo/TransformationMatrixCairo.cpp

@@list(APPEND WebCore_SOURCES
4646 platform/graphics/win/MediaPlayerPrivateMediaFoundation.cpp
4747 platform/graphics/win/SimpleFontDataCairoWin.cpp
4848
49  platform/image-decoders/cairo/ImageDecoderCairo.cpp
 49 platform/image-decoders/cairo/BitmapPixelsCairo.cpp
5050
5151 platform/network/NetworkStorageSessionStub.cpp
5252

Source/WebCore/WebCore.xcodeproj/project.pbxproj

14841484 375CD232119D43C800A2A859 /* Hyphenation.h in Headers */ = {isa = PBXBuildFile; fileRef = 375CD231119D43C800A2A859 /* Hyphenation.h */; };
14851485 376DCCE113B4F966002EBEFC /* TextRun.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 376DCCE013B4F966002EBEFC /* TextRun.cpp */; };
14861486 3774ABA50FA21EB400AD7DE9 /* OverlapTestRequestClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 3774ABA30FA21EB400AD7DE9 /* OverlapTestRequestClient.h */; settings = {ATTRIBUTES = (Private, ); }; };
1487  377A3A9015EFCE9B0059F5C7 /* BitmapImageCG.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 377A3A8F15EFCE9A0059F5C7 /* BitmapImageCG.cpp */; };
 1487 377A3A9015EFCE9B0059F5C7 /* PlatformImageCG.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 377A3A8F15EFCE9A0059F5C7 /* PlatformImageCG.cpp */; };
14881488 37919C230B7D188600A56998 /* PositionIterator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37919C210B7D188600A56998 /* PositionIterator.cpp */; };
14891489 37919C240B7D188600A56998 /* PositionIterator.h in Headers */ = {isa = PBXBuildFile; fileRef = 37919C220B7D188600A56998 /* PositionIterator.h */; settings = {ATTRIBUTES = (); }; };
14901490 3792917A1985EF3900F4B661 /* CredentialBase.h in Headers */ = {isa = PBXBuildFile; fileRef = 379291781985EF3900F4B661 /* CredentialBase.h */; settings = {ATTRIBUTES = (Private, ); }; };

23252325 53ED3FDF167A88E7006762E6 /* JSInternalSettingsGenerated.h in Headers */ = {isa = PBXBuildFile; fileRef = 53ED3FDD167A88E7006762E6 /* JSInternalSettingsGenerated.h */; };
23262326 53EF766B16530A61004CBE49 /* SettingsMacros.h in Headers */ = {isa = PBXBuildFile; fileRef = 53EF766A16530A61004CBE49 /* SettingsMacros.h */; };
23272327 53EF766C16531994004CBE49 /* SettingsMacros.h in Copy Generated Headers */ = {isa = PBXBuildFile; fileRef = 53EF766A16530A61004CBE49 /* SettingsMacros.h */; };
 2328 5504E4CB1D3557B200FE5088 /* BitmapPixels.h in Headers */ = {isa = PBXBuildFile; fileRef = 5504E4CA1D35532D00FE5088 /* BitmapPixels.h */; settings = {ATTRIBUTES = (Private, ); }; };
23282329 550A0BC9085F6039007353D6 /* QualifiedName.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 550A0BC7085F6039007353D6 /* QualifiedName.cpp */; };
23292330 550A0BCA085F6039007353D6 /* QualifiedName.h in Headers */ = {isa = PBXBuildFile; fileRef = 550A0BC8085F6039007353D6 /* QualifiedName.h */; settings = {ATTRIBUTES = (Private, ); }; };
23302331 555B87EC1CAAF0AB00349425 /* ImageDecoderCG.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 555B87EA1CAAF0AB00349425 /* ImageDecoderCG.cpp */; };
23312332 555B87ED1CAAF0AB00349425 /* ImageDecoderCG.h in Headers */ = {isa = PBXBuildFile; fileRef = 555B87EB1CAAF0AB00349425 /* ImageDecoderCG.h */; };
 2333 5574F0871D02790900B9F14C /* PlatformImage.h in Headers */ = {isa = PBXBuildFile; fileRef = 5574F0851D02744400B9F14C /* PlatformImage.h */; settings = {ATTRIBUTES = (Private, ); }; };
 2334 55CBA6A11D1DF2E100451860 /* ImageFrameData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 55CBA69F1D1DF2E100451860 /* ImageFrameData.cpp */; };
 2335 55CBA6A21D1DF2E100451860 /* ImageFrameData.h in Headers */ = {isa = PBXBuildFile; fileRef = 55CBA6A01D1DF2E100451860 /* ImageFrameData.h */; settings = {ATTRIBUTES = (Private, ); }; };
23322336 572A7F211C6E5719009C6149 /* SimulatedClick.h in Headers */ = {isa = PBXBuildFile; fileRef = 572A7F201C6E5719009C6149 /* SimulatedClick.h */; };
23332337 572A7F231C6E5A66009C6149 /* SimulatedClick.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 572A7F221C6E5A66009C6149 /* SimulatedClick.cpp */; };
23342338 57EF5E601D20C83900171E60 /* TextCodecReplacement.h in Headers */ = {isa = PBXBuildFile; fileRef = 57EF5E5F1D20C83900171E60 /* TextCodecReplacement.h */; };

90619065 376DCCE013B4F966002EBEFC /* TextRun.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TextRun.cpp; sourceTree = "<group>"; };
90629066 3772B09516535856000A49CA /* PopupOpeningObserver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PopupOpeningObserver.h; sourceTree = "<group>"; };
90639067 3774ABA30FA21EB400AD7DE9 /* OverlapTestRequestClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OverlapTestRequestClient.h; sourceTree = "<group>"; };
9064  377A3A8F15EFCE9A0059F5C7 /* BitmapImageCG.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = BitmapImageCG.cpp; sourceTree = "<group>"; };
 9068 377A3A8F15EFCE9A0059F5C7 /* PlatformImageCG.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PlatformImageCG.cpp; sourceTree = "<group>"; };
90659069 37919C210B7D188600A56998 /* PositionIterator.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = PositionIterator.cpp; sourceTree = "<group>"; };
90669070 37919C220B7D188600A56998 /* PositionIterator.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = PositionIterator.h; sourceTree = "<group>"; };
90679071 379291781985EF3900F4B661 /* CredentialBase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CredentialBase.h; sourceTree = "<group>"; };

99899993 53ED3FDC167A88E7006762E6 /* JSInternalSettingsGenerated.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSInternalSettingsGenerated.cpp; sourceTree = "<group>"; };
99909994 53ED3FDD167A88E7006762E6 /* JSInternalSettingsGenerated.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSInternalSettingsGenerated.h; sourceTree = "<group>"; };
99919995 53EF766A16530A61004CBE49 /* SettingsMacros.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SettingsMacros.h; sourceTree = "<group>"; };
 9996 5504E4CA1D35532D00FE5088 /* BitmapPixels.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BitmapPixels.h; sourceTree = "<group>"; };
99929997 550A0BC7085F6039007353D6 /* QualifiedName.cpp */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.cpp.cpp; path = QualifiedName.cpp; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
99939998 550A0BC8085F6039007353D6 /* QualifiedName.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = QualifiedName.h; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
99949999 555B87EA1CAAF0AB00349425 /* ImageDecoderCG.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ImageDecoderCG.cpp; sourceTree = "<group>"; };
999510000 555B87EB1CAAF0AB00349425 /* ImageDecoderCG.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ImageDecoderCG.h; sourceTree = "<group>"; };
 10001 5574F0851D02744400B9F14C /* PlatformImage.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PlatformImage.h; sourceTree = "<group>"; };
 10002 55CBA69F1D1DF2E100451860 /* ImageFrameData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ImageFrameData.cpp; sourceTree = "<group>"; };
 10003 55CBA6A01D1DF2E100451860 /* ImageFrameData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ImageFrameData.h; sourceTree = "<group>"; };
999610004 55D408F71A7C631800C78450 /* SVGImageClients.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SVGImageClients.h; sourceTree = "<group>"; };
999710005 572A7F201C6E5719009C6149 /* SimulatedClick.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SimulatedClick.h; sourceTree = "<group>"; };
999810006 572A7F221C6E5A66009C6149 /* SimulatedClick.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SimulatedClick.cpp; sourceTree = "<group>"; };

2202422032 B27535290B053814002CE64F /* cg */ = {
2202522033 isa = PBXGroup;
2202622034 children = (
22027  377A3A8F15EFCE9A0059F5C7 /* BitmapImageCG.cpp */,
2202822035 0FCF33230F2B9715004B6795 /* ColorCG.cpp */,
2202922036 B275352B0B053814002CE64F /* FloatPointCG.cpp */,
2203022037 B275352C0B053814002CE64F /* FloatRectCG.cpp */,

2205122058 A80A38FD0E50CC8200A25EBC /* PatternCG.cpp */,
2205222059 B27535360B053814002CE64F /* PDFDocumentImage.cpp */,
2205322060 B27535370B053814002CE64F /* PDFDocumentImage.h */,
 22061 377A3A8F15EFCE9A0059F5C7 /* PlatformImageCG.cpp */,
2205422062 1FC40FB81655C5910040F29E /* SubimageCacheWithTimer.cpp */,
2205522063 1FC40FB71655C5910040F29E /* SubimageCacheWithTimer.h */,
2205622064 B275352A0B053814002CE64F /* TransformationMatrixCG.cpp */,

2211822126 BEF29EE91715DD0900C4B4C9 /* AudioTrackPrivate.h */,
2211922127 A89943270B42338700D7C802 /* BitmapImage.cpp */,
2212022128 A89943260B42338700D7C802 /* BitmapImage.h */,
 22129 5504E4CA1D35532D00FE5088 /* BitmapPixels.h */,
2212122130 CDDE02E918B3DFC700CF7FF1 /* CDMSession.h */,
2212222131 B27535380B053814002CE64F /* Color.cpp */,
2212322132 B27535390B053814002CE64F /* Color.h */,

2220222211 43D2597613C816F400608559 /* ImageBuffer.cpp */,
2220322212 B2A10B910B3818BD00099AA4 /* ImageBuffer.h */,
2220422213 22BD9F7D1353625C009BD102 /* ImageBufferData.h */,
 22214 55CBA69F1D1DF2E100451860 /* ImageFrameData.cpp */,
 22215 55CBA6A01D1DF2E100451860 /* ImageFrameData.h */,
2220522216 BC7F44A70B9E324E00A9D081 /* ImageObserver.h */,
2220622217 A8748D7412CC3F89001FBA41 /* ImageOrientation.cpp */,
2220722218 A8748D6612CC3763001FBA41 /* ImageOrientation.h */,

2225122262 2D5002FA1B56D7990020AAF7 /* PathUtilities.h */,
2225222263 A8FA6E5C0E4CFDED00D5CF49 /* Pattern.cpp */,
2225322264 A8FA6E5B0E4CFDED00D5CF49 /* Pattern.h */,
 22265 5574F0851D02744400B9F14C /* PlatformImage.h */,
2225422266 0562F9601573F88F0031CA16 /* PlatformLayer.h */,
2225522267 CEEFCD7B19DB33DC003876D7 /* PlatformMediaResourceLoader.h */,
2225622268 072847E216EBC5B00043CFA4 /* PlatformTextTrack.h */,

2601826030 85E711B90AC5D5350053270F /* DOMHTMLMapElementInternal.h in Headers */,
2601926031 BC51579F0C03BBD3008BB0EE /* DOMHTMLMarqueeElement.h in Headers */,
2602026032 BC5156EA0C03B741008BB0EE /* DOMHTMLMarqueeElementInternal.h in Headers */,
 26033 5574F0871D02790900B9F14C /* PlatformImage.h in Headers */,
2602126034 2DEC66551C82D0410099846A /* DOMHTMLMediaElement.h in Headers */,
2602226035 2DEC66511C82D0160099846A /* DOMHTMLMediaElementInternal.h in Headers */,
2602326036 85BA4D130AA688680088052D /* DOMHTMLMenuElement.h in Headers */,

2645926472 D359D78A129CA2710006E5D2 /* HTMLDetailsElement.h in Headers */,
2646026473 A8EA79FA0A1916DF00A8EF5F /* HTMLDirectoryElement.h in Headers */,
2646126474 A8EA7CB70A192B9C00A8EF5F /* HTMLDivElement.h in Headers */,
 26475 55CBA6A21D1DF2E100451860 /* ImageFrameData.h in Headers */,
2646226476 A8EA79F70A1916DF00A8EF5F /* HTMLDListElement.h in Headers */,
2646326477 93F198E508245E59001E9ABC /* HTMLDocument.h in Headers */,
2646426478 977B3867122883E900B81FF8 /* HTMLDocumentParser.h in Headers */,

2835928373 B22279930D00BF220071B782 /* SVGAnimateMotionElement.h in Headers */,
2836028374 B22279950D00BF220071B782 /* SVGAnimateTransformElement.h in Headers */,
2836128375 B22279980D00BF220071B782 /* SVGAnimationElement.h in Headers */,
 28376 5504E4CB1D3557B200FE5088 /* BitmapPixels.h in Headers */,
2836228377 439D334513A6911C00C20F4F /* SVGAnimatorFactory.h in Headers */,
2836328378 08FB3F8413BC754C0099FC18 /* SVGAttributeToPropertyMap.h in Headers */,
2836428379 B222799C0D00BF220071B782 /* SVGCircleElement.h in Headers */,

2941129426 FDC54F041399B0DA008D9117 /* BiquadFilterNode.cpp in Sources */,
2941229427 FD31602612B0267600C1A359 /* BiquadProcessor.cpp in Sources */,
2941329428 A89943290B42338800D7C802 /* BitmapImage.cpp in Sources */,
29414  377A3A9015EFCE9B0059F5C7 /* BitmapImageCG.cpp in Sources */,
 29429 377A3A9015EFCE9B0059F5C7 /* PlatformImageCG.cpp in Sources */,
2941529430 976D6C78122B8A3D001FD1F7 /* Blob.cpp in Sources */,
2941629431 2EDEF1F3121B0EFC00726DB2 /* BlobData.cpp in Sources */,
2941729432 E1D31CDC19196020001005A3 /* BlobDataFileReference.cpp in Sources */,

2977429789 2E2D99E810E2BC1C00496337 /* DOMBlob.mm in Sources */,
2977529790 85089CD80A98C42800A275AA /* DOMCDATASection.mm in Sources */,
2977629791 85ACA9870A9B520300671E90 /* DOMCharacterData.mm in Sources */,
 29792 55CBA6A11D1DF2E100451860 /* ImageFrameData.cpp in Sources */,
2977729793 85089CDA0A98C42800A275AA /* DOMComment.mm in Sources */,
2977829794 978D07BE145A0F6C0096908D /* DOMCoreException.cpp in Sources */,
2977929795 858C38A60AA8F20400B187A4 /* DOMCounter.mm in Sources */,

Source/WebCore/bindings/objc/DOM.mm

@@- (void)getPreviewSnapshotImage:(CGImageRef*)cgImage andRects:(NSArray **)rects
606606
607607 if (textIndicator) {
608608 if (Image* image = textIndicator->contentImage())
609  *cgImage = (CGImageRef)CFAutorelease(CGImageRetain(image->getCGImageRef()));
 609 *cgImage = image->nativeImage().autorelease();
610610 }
611611
612612 RetainPtr<NSMutableArray> rectArray = adoptNS([[NSMutableArray alloc] init]);

Source/WebCore/page/mac/TextIndicatorWindow.mm

@@- (instancetype)initWithFrame:(NSRect)frame textIndicator:(PassRefPtr<TextIndica
162162 contentsImageLogicalSize.scale(1 / _textIndicator->contentImageScaleFactor());
163163 RetainPtr<CGImageRef> contentsImage;
164164 if (indicatorWantsContentCrossfade(*_textIndicator))
165  contentsImage = _textIndicator->contentImageWithHighlight()->getCGImageRef();
 165 contentsImage = _textIndicator->contentImageWithHighlight()->nativeImage();
166166 else
167  contentsImage = _textIndicator->contentImage()->getCGImageRef();
 167 contentsImage = _textIndicator->contentImage()->nativeImage();
168168
169169 RetainPtr<NSMutableArray> bounceLayers = adoptNS([[NSMutableArray alloc] init]);
170170

@@static RetainPtr<CAKeyframeAnimation> createBounceAnimation(CFTimeInterval durat
265265static RetainPtr<CABasicAnimation> createContentCrossfadeAnimation(CFTimeInterval duration, TextIndicator& textIndicator)
266266{
267267 RetainPtr<CABasicAnimation> crossfadeAnimation = [CABasicAnimation animationWithKeyPath:@"contents"];
268  RetainPtr<CGImageRef> contentsImage = textIndicator.contentImage()->getCGImageRef();
 268 RetainPtr<CGImageRef> contentsImage = textIndicator.contentImage()->nativeImage();
269269 [crossfadeAnimation setToValue:(id)contentsImage.get()];
270270 [crossfadeAnimation setFillMode:kCAFillModeForwards];
271271 [crossfadeAnimation setRemovedOnCompletion:NO];

Source/WebCore/platform/graphics/BitmapImage.cpp

@@BitmapImage::BitmapImage(NativeImagePtr&& image, ImageObserver* observer)
6868 , m_haveFrameCount(true)
6969 , m_animationFinishedWhenCatchingUp(false)
7070{
 71 m_frames.reserveInitialCapacity(1);
 72 m_frames.uncheckedAppend(WTFMove(image));
 73
7174 // Since we don't have a decoder, we can't figure out the image orientation.
7275 // Set m_sizeRespectingOrientation to be the same as m_size so it's not 0x0.
73  m_sizeRespectingOrientation = m_size = NativeImage::size(image);
 76 m_sizeRespectingOrientation = m_size = m_frames[0].size();
7477 m_decodedSize = m_size.area() * 4;
75 
76  m_frames.grow(1);
77  m_frames[0].m_hasAlpha = NativeImage::hasAlpha(image);
78  m_frames[0].m_haveMetadata = true;
79  m_frames[0].m_image = WTFMove(image);
8078}
8179
8280BitmapImage::~BitmapImage()

@@bool BitmapImage::haveFrameImageAtIndex(size_t index)
105103 if (index >= m_frames.size())
106104 return false;
107105
108  return m_frames[index].m_image;
 106 return m_frames[index].hasImage();
109107}
110108
111109bool BitmapImage::hasSingleSecurityOrigin() const

@@void BitmapImage::destroyDecodedData(bool destroyAll)
125123 // The underlying frame isn't actually changing (we're just trying to
126124 // save the memory for the framebuffer data), so we don't need to clear
127125 // the metadata.
128  unsigned frameBytes = m_frames[i].m_frameBytes;
129  if (m_frames[i].clear(false))
130  frameBytesCleared += frameBytes;
 126 frameBytesCleared += m_frames[i].clear(ImageFrameData::Caching::Metadata);
131127 }
132128
133129 m_source.clear(destroyAll, clearBeforeFrame, data(), m_allDataReceived);

@@void BitmapImage::destroyDecodedDataIfNecessary(bool destroyAll)
150146 return;
151147
152148 unsigned allFrameBytes = 0;
153  for (size_t i = 0; i < m_frames.size(); ++i)
154  allFrameBytes += m_frames[i].usedFrameBytes();
 149 for (auto& frame : m_frames)
 150 allFrameBytes += frame.frameBytes();
155151
156152 if (allFrameBytes > largeAnimationCutoff) {
157153 LOG(Images, "BitmapImage %p destroyDecodedDataIfNecessary destroyingData: allFrameBytes=%u cutoff=%u", this, allFrameBytes, largeAnimationCutoff);

@@void BitmapImage::destroyMetadataAndNotify(unsigned frameBytesCleared, ClearedSo
177173 imageObserver()->decodedSizeChanged(this, -safeCast<int>(frameBytesCleared));
178174}
179175
180 void BitmapImage::cacheFrame(size_t index, SubsamplingLevel subsamplingLevel, ImageFrameCaching frameCaching)
 176void BitmapImage::cacheFrame(size_t index, SubsamplingLevel subsamplingLevel, ImageFrameData::Caching caching)
181177{
182178 size_t numFrames = frameCount();
183179 ASSERT(m_decodedSize == 0 || numFrames > 1);

@@void BitmapImage::cacheFrame(size_t index, SubsamplingLevel subsamplingLevel, Im
185181 if (m_frames.size() < numFrames)
186182 m_frames.grow(numFrames);
187183
188  if (frameCaching == CacheMetadataAndFrame) {
189  m_frames[index].m_image = m_source.createFrameImageAtIndex(index, subsamplingLevel);
190  m_frames[index].m_subsamplingLevel = subsamplingLevel;
191  }
192 
193  m_frames[index].m_orientation = m_source.orientationAtIndex(index);
194  m_frames[index].m_haveMetadata = true;
195  m_frames[index].m_isComplete = m_source.frameIsCompleteAtIndex(index);
 184 m_frames[index] = m_source.createFrameDataAtIndex(index, subsamplingLevel, caching);
196185
197  if (repetitionCount(false) != cAnimationNone)
198  m_frames[index].m_duration = m_source.frameDurationAtIndex(index);
 186 LOG(Images, "BitmapImage %p cacheFrame %lu (%s%u bytes, complete %d)", this, index, caching == ImageFrameData::Caching::Metadata ? "metadata only, " : "", m_frames[index].frameBytes(), m_frames[index].isComplete());
199187
200  m_frames[index].m_hasAlpha = m_source.frameHasAlphaAtIndex(index);
201  m_frames[index].m_frameBytes = m_source.frameBytesAtIndex(index, subsamplingLevel);
202 
203  LOG(Images, "BitmapImage %p cacheFrame %lu (%s%u bytes, complete %d)", this, index, frameCaching == CacheMetadataOnly ? "metadata only, " : "", m_frames[index].m_frameBytes, m_frames[index].m_isComplete);
204 
205  if (m_frames[index].m_image) {
206  int deltaBytes = safeCast<int>(m_frames[index].m_frameBytes);
 188 if (m_frames[index].hasImage()) {
 189 int deltaBytes = safeCast<int>(m_frames[index].frameBytes());
207190 m_decodedSize += deltaBytes;
208191 // The fully-decoded frame will subsume the partially decoded data used
209192 // to determine image properties.

@@bool BitmapImage::dataChanged(bool allDataReceived)
288271 // frame affected by appending new data here. Thus we have to clear all the
289272 // incomplete frames to be safe.
290273 unsigned frameBytesCleared = 0;
291  for (size_t i = 0; i < m_frames.size(); ++i) {
 274 for (auto& frame : m_frames) {
292275 // NOTE: Don't call frameIsCompleteAtIndex() here, that will try to
293276 // decode any uncached (i.e. never-decoded or
294277 // cleared-on-a-previous-pass) frames!
295  unsigned frameBytes = m_frames[i].m_frameBytes;
296  if (m_frames[i].m_haveMetadata && !m_frames[i].m_isComplete)
297  frameBytesCleared += (m_frames[i].clear(true) ? frameBytes : 0);
 278 if (frame.hasMetadata() && !frame.isComplete())
 279 frameBytesCleared += frame.clear(ImageFrameData::Caching::Empty);
298280 }
299281 destroyMetadataAndNotify(frameBytesCleared, ClearedSource::No);
300282#else
301283 // FIXME: why is this different for iOS?
302284 int deltaBytes = 0;
303285 if (!m_frames.isEmpty()) {
304  int bytes = m_frames[m_frames.size() - 1].m_frameBytes;
305  if (m_frames[m_frames.size() - 1].clear(true)) {
 286 if (int bytes = m_frames[m_frames.size() - 1].clear(ImageFrameData::Caching::Empty)) {
306287 deltaBytes += bytes;
307288 deltaBytes += m_decodedPropertiesSize;
308289 m_decodedPropertiesSize = 0;

@@bool BitmapImage::isSizeAvailable()
366347 return m_sizeAvailable;
367348}
368349
369 bool BitmapImage::ensureFrameIsCached(size_t index, ImageFrameCaching frameCaching)
 350bool BitmapImage::ensureFrameIsCached(size_t index, ImageFrameData::Caching caching)
370351{
371352 if (index >= frameCount())
372353 return false;
373354
374355 if (index >= m_frames.size()
375  || (frameCaching == CacheMetadataAndFrame && !m_frames[index].m_image)
376  || (frameCaching == CacheMetadataOnly && !m_frames[index].m_haveMetadata))
377  cacheFrame(index, 0, frameCaching);
 356 || (caching == ImageFrameData::Caching::MetadataAndImage && !m_frames[index].hasImage())
 357 || (caching == ImageFrameData::Caching::Metadata && !m_frames[index].hasMetadata()))
 358 cacheFrame(index, 0, caching);
378359
379360 return true;
380361}

@@NativeImagePtr BitmapImage::frameImageAtIndex(size_t index, float presentationSc
388369
389370 // We may have cached a frame with a higher subsampling level, in which case we need to
390371 // re-decode with a lower level.
391  if (index < m_frames.size() && m_frames[index].m_image && subsamplingLevel < m_frames[index].m_subsamplingLevel) {
 372 if (index < m_frames.size() && m_frames[index].hasImage() && subsamplingLevel < m_frames[index].subsamplingLevel()) {
392373 // If the image is already cached, but at too small a size, re-decode a larger version.
393  int sizeChange = -m_frames[index].m_frameBytes;
394  m_frames[index].clear(true);
 374 int sizeChange = -m_frames[index].clear(ImageFrameData::Caching::Empty);
395375 invalidatePlatformData();
396376 m_decodedSize += sizeChange;
397377 if (imageObserver())

@@NativeImagePtr BitmapImage::frameImageAtIndex(size_t index, float presentationSc
399379 }
400380
401381 // If we haven't fetched a frame yet, do so.
402  if (index >= m_frames.size() || !m_frames[index].m_image)
403  cacheFrame(index, subsamplingLevel, CacheMetadataAndFrame);
 382 if (index >= m_frames.size() || !m_frames[index].hasImage())
 383 cacheFrame(index, subsamplingLevel, ImageFrameData::Caching::MetadataAndImage);
 384
 385 return m_frames[index].image();
 386}
 387
 388NativeImagePtr BitmapImage::nativeImage()
 389{
 390 return frameImageAtIndex(0);
 391}
 392
 393NativeImagePtr BitmapImage::nativeImageOfSize(const IntSize& size)
 394{
 395 size_t count = frameCount();
 396
 397 for (size_t i = 0; i < count; ++i) {
 398 auto image = frameImageAtIndex(i);
 399 if (image && PlatformImage(image).size() == size)
 400 return image;
 401 }
 402
 403 // Fallback to the first frame image if we can't find the right size
 404 return frameImageAtIndex(0);
 405}
 406
 407NativeImagePtr BitmapImage::nativeImageForCurrentFrame()
 408{
 409 return frameImageAtIndex(m_currentFrame);
 410}
404411
405  return m_frames[index].m_image;
 412Vector<NativeImagePtr> BitmapImage::framesNativeImages()
 413{
 414 Vector<NativeImagePtr> images;
 415 size_t count = frameCount();
 416
 417 for (size_t i = 0; i < count; ++i) {
 418 if (auto image = frameImageAtIndex(i))
 419 images.append(image);
 420 }
 421
 422 return images;
406423}
407424
408425bool BitmapImage::frameIsCompleteAtIndex(size_t index)
409426{
410  if (!ensureFrameIsCached(index, CacheMetadataOnly))
 427 if (!ensureFrameIsCached(index, ImageFrameData::Caching::Metadata))
411428 return false;
412429
413  return m_frames[index].m_isComplete;
 430 return m_frames[index].isComplete();
414431}
415432
416433float BitmapImage::frameDurationAtIndex(size_t index)
417434{
418  if (!ensureFrameIsCached(index, CacheMetadataOnly))
 435 if (!ensureFrameIsCached(index, ImageFrameData::Caching::Metadata))
419436 return 0;
420437
421  return m_frames[index].m_duration;
422 }
423 
424 NativeImagePtr BitmapImage::nativeImageForCurrentFrame()
425 {
426  return frameImageAtIndex(currentFrame());
 438 return m_frames[index].duration();
427439}
428440
429441bool BitmapImage::frameHasAlphaAtIndex(size_t index)
430442{
431  if (!ensureFrameIsCached(index, CacheMetadataOnly))
 443 if (!ensureFrameIsCached(index, ImageFrameData::Caching::Metadata))
432444 return true;
433445
434  if (m_frames[index].m_haveMetadata)
435  return m_frames[index].m_hasAlpha;
 446 if (m_frames[index].hasMetadata())
 447 return m_frames[index].hasAlpha();
436448
437449 return m_source.frameHasAlphaAtIndex(index);
438450}

@@bool BitmapImage::currentFrameKnownToBeOpaque()
444456
445457ImageOrientation BitmapImage::frameOrientationAtIndex(size_t index)
446458{
447  if (!ensureFrameIsCached(index, CacheMetadataOnly))
 459 if (!ensureFrameIsCached(index, ImageFrameData::Caching::Metadata))
448460 return ImageOrientation();
449461
450  if (m_frames[index].m_haveMetadata)
451  return m_frames[index].m_orientation;
 462 if (m_frames[index].hasMetadata())
 463 return m_frames[index].orientation();
452464
453465 return m_source.orientationAtIndex(index);
454466}

@@Color BitmapImage::singlePixelSolidColor()
700712 return Color();
701713
702714 ASSERT(m_frames.size());
703  m_solidColor = NativeImage::singlePixelSolidColor(m_frames[0].m_image.get());
 715 m_solidColor = m_frames[0].singlePixelSolidColor();
704716
705717 ASSERT(m_solidColor);
706718 return m_solidColor.value();
707719}
708720
 721bool BitmapImage::isAlmostSolidColor()
 722{
 723 if (frameCount() != 1)
 724 return false;
 725
 726 return ensureFrameIsCached(0) && m_frames[0].isAlmostSolidColor();
 727}
 728
709729bool BitmapImage::canAnimate()
710730{
711731 return shouldAnimate() && frameCount() > 1;
712732}
713733
 734void BitmapImage::draw(GraphicsContext& context, const FloatRect& destRect, const FloatRect& srcRect, CompositeOperator op, BlendMode mode, ImageOrientationDescription description)
 735{
 736 if (destRect.isEmpty() || srcRect.isEmpty())
 737 return;
 738
 739#if PLATFORM(IOS)
 740 startAnimation(DoNotCatchUp);
 741#else
 742 startAnimation();
 743#endif
 744
 745 Color color = singlePixelSolidColor();
 746 if (color.isValid()) {
 747 fillWithSolidColor(context, destRect, color, op);
 748 return;
 749 }
 750
 751 auto image = frameImageAtIndex(m_currentFrame, PlatformImage::subsamplingScale(context, destRect, srcRect));
 752 if (!image) // If it's too early we won't have an image yet.
 753 return;
 754
 755 ImageOrientation orientation(description.imageOrientation());
 756 if (description.respectImageOrientation() == RespectImageOrientation)
 757 orientation = frameOrientationAtIndex(m_currentFrame);
 758
 759 PlatformImage(image).draw(context, destRect, srcRect, m_size, op, mode, orientation);
 760
 761 if (imageObserver())
 762 imageObserver()->didDraw(this);
 763}
 764
714765void BitmapImage::dump(TextStream& ts) const
715766{
716767 Image::dump(ts);

Source/WebCore/platform/graphics/BitmapImage.h

2828#ifndef BitmapImage_h
2929#define BitmapImage_h
3030
31 #include "Image.h"
3231#include "Color.h"
 32#include "Image.h"
 33#include "ImageFrameData.h"
3334#include "ImageOrientation.h"
3435#include "ImageSource.h"
3536#include "IntSize.h"
 37#include "PlatformImage.h"
3638
3739#if USE(CG) || USE(APPKIT)
3840#include <wtf/RetainPtr.h>

@@typedef struct HBITMAP__ *HBITMAP;
4749#endif
4850
4951namespace WebCore {
50  struct FrameData;
51 }
52 
53 namespace WTF {
54  template<> struct VectorTraits<WebCore::FrameData> : public SimpleClassVectorTraits {
55  static const bool canInitializeWithMemset = false; // Not all FrameData members initialize to 0.
56  };
57 }
58 
59 namespace WebCore {
6052
6153class Timer;
6254
63 namespace NativeImage {
64  IntSize size(const NativeImagePtr&);
65  bool hasAlpha(const NativeImagePtr&);
66  Color singlePixelSolidColor(const NativeImagePtr&);
67 }
68 
69 // ================================================
70 // FrameData Class
71 // ================================================
72 
73 struct FrameData {
74 public:
75  FrameData()
76  : m_haveMetadata(false)
77  , m_isComplete(false)
78  , m_hasAlpha(true)
79  {
80  }
81 
82  ~FrameData()
83  {
84  clear(true);
85  }
86 
87  // Clear the cached image data on the frame, and (optionally) the metadata.
88  // Returns whether there was cached image data to clear.
89  bool clear(bool clearMetadata);
90 
91  unsigned usedFrameBytes() const { return m_image ? m_frameBytes : 0; }
92 
93  NativeImagePtr m_image;
94  ImageOrientation m_orientation { DefaultImageOrientation };
95  SubsamplingLevel m_subsamplingLevel { 0 };
96  float m_duration { 0 };
97  bool m_haveMetadata : 1;
98  bool m_isComplete : 1;
99  bool m_hasAlpha : 1;
100  unsigned m_frameBytes { 0 };
101 };
102 
103 // =================================================
104 // BitmapImage Class
105 // =================================================
106 
10755class BitmapImage final : public Image {
10856 friend class GeneratedImage;
10957 friend class CrossfadeGeneratedImage;

@@public:
155103 CFDataRef getTIFFRepresentation() override;
156104#endif
157105
158 #if USE(CG)
159  WEBCORE_EXPORT CGImageRef getCGImageRef() override;
160  CGImageRef getFirstCGImageRefOfSize(const IntSize&) override;
161  RetainPtr<CFArrayRef> getCGImageArray() override;
162 #endif
163 
164106#if PLATFORM(WIN)
165107 bool getHBITMAP(HBITMAP) override;
166108 bool getHBITMAPOfSize(HBITMAP, const IntSize*) override;

@@public:
174116 Evas_Object* getEvasObject(Evas*) override;
175117#endif
176118
 119 WEBCORE_EXPORT NativeImagePtr nativeImage() override;
 120 NativeImagePtr nativeImageOfSize(const IntSize&) override;
177121 NativeImagePtr nativeImageForCurrentFrame() override;
178122 ImageOrientation orientationForCurrentFrame() override { return frameOrientationAtIndex(currentFrame()); }
 123 Vector<NativeImagePtr> framesNativeImages() override;
 124
 125 WEBCORE_EXPORT bool isAlmostSolidColor();
179126
180127 bool currentFrameKnownToBeOpaque() override;
181128

@@protected:
215162 size_t frameCount();
216163
217164 NativeImagePtr frameImageAtIndex(size_t, float presentationScaleHint = 1);
218  NativeImagePtr copyUnscaledFrameImageAtIndex(size_t);
219165
220166 bool haveFrameImageAtIndex(size_t);
221167

@@protected:
225171 ImageOrientation frameOrientationAtIndex(size_t);
226172
227173 // Decodes and caches a frame. Never accessed except internally.
228  enum ImageFrameCaching { CacheMetadataOnly, CacheMetadataAndFrame };
229  void cacheFrame(size_t index, SubsamplingLevel, ImageFrameCaching = CacheMetadataAndFrame);
 174 void cacheFrame(size_t index, SubsamplingLevel, ImageFrameData::Caching = ImageFrameData::Caching::MetadataAndImage);
230175
231176 // Called before accessing m_frames[index] for info without decoding. Returns false on index out of bounds.
232  bool ensureFrameIsCached(size_t index, ImageFrameCaching = CacheMetadataAndFrame);
 177 bool ensureFrameIsCached(size_t index, ImageFrameData::Caching = ImageFrameData::Caching::MetadataAndImage);
233178
234179 // Called to invalidate cached data. When |destroyAll| is true, we wipe out
235180 // the entire frame buffer cache and tell the image source to destroy

@@private:
292237 mutable IntSize m_sizeRespectingOrientation;
293238
294239 size_t m_currentFrame { 0 }; // The index of the current frame of animation.
295  Vector<FrameData, 1> m_frames; // An array of the cached frames of the animation. We have to ref frames to pin them in the cache.
 240 Vector<ImageFrameData, 1> m_frames; // An array of the cached frames of the animation. We have to ref frames to pin them in the cache.
296241
297242 std::unique_ptr<Timer> m_frameTimer;
298243 int m_repetitionCount { cAnimationNone }; // How many total animation loops we should do. This will be cAnimationNone if this image type is incapable of animation.

Source/WebCore/platform/graphics/BitmapPixels.h

 1/*
 2 * Copyright (C) 2016 Apple Inc. All rights reserved.
 3 *
 4 * Redistribution and use in source and binary forms, with or without
 5 * modification, are permitted provided that the following conditions
 6 * are met:
 7 * 1. Redistributions of source code must retain the above copyright
 8 * notice, this list of conditions and the following disclaimer.
 9 * 2. Redistributions in binary form must reproduce the above copyright
 10 * notice, this list of conditions and the following disclaimer in the
 11 * documentation and/or other materials provided with the distribution.
 12 *
 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 24 */
 25
 26#pragma once
 27
 28#include "Color.h"
 29#include "IntRect.h"
 30#include "IntSize.h"
 31#include "NativeImagePtr.h"
 32
 33#include <wtf/Vector.h>
 34
 35namespace WebCore {
 36
 37class BitmapPixels {
 38public:
 39 static std::unique_ptr<BitmapPixels> create(const IntSize& size, bool premultiplyAlpha)
 40 {
 41 return std::make_unique<BitmapPixels>(size, premultiplyAlpha);
 42 }
 43
 44 static std::unique_ptr<BitmapPixels> create(const BitmapPixels& other)
 45 {
 46 return std::make_unique<BitmapPixels>(other);
 47 }
 48
 49 BitmapPixels(const IntSize& size, bool premultiplyAlpha = true)
 50 : m_premultiplyAlpha(premultiplyAlpha)
 51 {
 52 ASSERT(!size.isEmpty());
 53 setSize(size);
 54 }
 55
 56 BitmapPixels(const BitmapPixels& other)
 57 {
 58 if (this == &other)
 59 return;
 60
 61 m_backingStore = other.m_backingStore;
 62 m_pixels = m_backingStore.data();
 63 m_size = other.m_size;
 64 m_rect = other.m_rect;
 65 m_premultiplyAlpha = other.m_premultiplyAlpha;
 66 }
 67
 68 NativeImagePtr image() const;
 69
 70 bool setSize(const IntSize& size)
 71 {
 72 if (!m_backingStore.tryReserveCapacity(size.area()))
 73 return false;
 74
 75 m_backingStore.resize(size.area());
 76 m_pixels = m_backingStore.data();
 77 m_size = size;
 78 m_rect = IntRect(IntPoint(), m_size);
 79 clear();
 80 return true;
 81 }
 82
 83 void setRect(const IntRect& rect)
 84 {
 85 ASSERT(!m_size.isEmpty());
 86 ASSERT(inBounds(rect));
 87 m_rect = rect;
 88 }
 89
 90 IntSize size() const { return m_size; }
 91 IntRect rect() const { return m_rect; }
 92
 93 RGBA32* at(int x, int y) const
 94 {
 95 return m_pixels + y * m_size.width() + x;
 96 }
 97
 98 void clear()
 99 {
 100 memset(m_pixels, 0, m_size.area() * sizeof(RGBA32));
 101 }
 102
 103 void clearRect(const IntRect& rect)
 104 {
 105 if (rect.isEmpty() || inBounds(rect))
 106 return;
 107
 108 size_t rectWidthInBytes = rect.width() * sizeof(RGBA32);
 109 RGBA32* start = at(rect.x(), rect.y());
 110 for (int i = 0; i < rect.height(); ++i) {
 111 memset(start, 0, rectWidthInBytes);
 112 start += m_size.width();
 113 }
 114 }
 115
 116 void repeatFirstRow(const IntRect& rect)
 117 {
 118 if (rect.isEmpty() || inBounds(rect))
 119 return;
 120
 121 size_t rectWidthInBytes = rect.width() * sizeof(RGBA32);
 122 RGBA32* src = at(rect.x(), rect.y());
 123 RGBA32* dest = src + m_size.width();
 124 for (int i = 1; i < rect.height(); ++i) {
 125 memcpy(dest, src, rectWidthInBytes);
 126 dest += m_size.width();
 127 }
 128 }
 129
 130 void setRGBA(int x, int y, unsigned r, unsigned g, unsigned b, unsigned a)
 131 {
 132 setRGBA(at(x, y), r, g, b, a);
 133 }
 134
 135 void setRGBA(RGBA32* dest, unsigned r, unsigned g, unsigned b, unsigned a)
 136 {
 137 if (!m_premultiplyAlpha || a >= 255)
 138 *dest = makeRGBA(r, g, b, a);
 139 else if (!a)
 140 *dest = 0;
 141 else
 142 *dest = makePremultipliedRGBA(r, g, b, a);
 143 }
 144
 145 void overRGBA(RGBA32* dest, unsigned r, unsigned g, unsigned b, unsigned a)
 146 {
 147 if (!a)
 148 return;
 149
 150 if (a >= 255 || !alphaChannel(*dest)) {
 151 setRGBA(dest, r, g, b, a);
 152 return;
 153 }
 154
 155 if (!m_premultiplyAlpha)
 156 *dest = makePremultipliedRGBA(redChannel(*dest), greenChannel(*dest), blueChannel(*dest), alphaChannel(*dest));
 157
 158 RGBA32 src = makeRGBA(r, g, b, a);
 159 *dest = Color(*dest).blend(src).rgb();
 160
 161 if (!m_premultiplyAlpha)
 162 *dest = makeUnPremultipliedRGBA(redChannel(*dest), greenChannel(*dest), blueChannel(*dest), alphaChannel(*dest));
 163 }
 164
 165 bool inBounds(const IntPoint& point) const
 166 {
 167 return IntRect(IntPoint(), m_size).contains(point);
 168 }
 169
 170 bool inBounds(const IntRect& rect) const
 171 {
 172 return IntRect(IntPoint(), m_size).contains(rect);
 173 }
 174
 175private:
 176 Vector<RGBA32> m_backingStore;
 177 RGBA32* m_pixels { nullptr };
 178 IntSize m_size;
 179 IntRect m_rect; // This will always just be the entire buffer except for GIF and PNG frames
 180 bool m_premultiplyAlpha { true };
 181};
 182
 183}

Source/WebCore/platform/graphics/Color.cpp

@@const RGBA32 Color::transparent;
4949static const RGBA32 lightenedBlack = 0xFF545454;
5050static const RGBA32 darkenedWhite = 0xFFABABAB;
5151
 52static inline unsigned multiply255(unsigned c)
 53{
 54 // c * 255
 55 // = c * (256 - 1)
 56 // = c * 256 - c
 57 return (c << 8) - c;
 58}
 59
 60static inline unsigned divide255(unsigned c)
 61{
 62 // c / 255
 63 // = c / 256 * (1 + 1 / 255)
 64 // = (c + c / 255) / 256
 65 // = (c + (c + c / 255) / 256) / 256
 66 // = (c + c / 256 + c / (255 x 256)) / 256
 67 // ~= (c + c / 256 + 1) / 256
 68 return (c + (c >> 8) + 1) >> 8;
 69}
 70
 71static inline unsigned divideCeil(unsigned c, unsigned d)
 72{
 73 return (c + d - 1) / d;
 74}
 75
 76static inline unsigned premultipliedChannel(unsigned c, unsigned a)
 77{
 78 return divide255(c * a);
 79}
 80
 81static inline unsigned unpremultipliedChannel(unsigned c, unsigned a)
 82{
 83 return divideCeil(multiply255(c), a);
 84}
 85
5286RGBA32 makeRGB(int r, int g, int b)
5387{
5488 return 0xFF000000 | std::max(0, std::min(r, 255)) << 16 | std::max(0, std::min(g, 255)) << 8 | std::max(0, std::min(b, 255));

@@RGBA32 makeRGBA(int r, int g, int b, int a)
5993 return std::max(0, std::min(a, 255)) << 24 | std::max(0, std::min(r, 255)) << 16 | std::max(0, std::min(g, 255)) << 8 | std::max(0, std::min(b, 255));
6094}
6195
 96RGBA32 makePremultipliedRGBA(int r, int g, int b, int a)
 97{
 98 return makeRGBA(premultipliedChannel(r, a), premultipliedChannel(g, a), premultipliedChannel(b, a), a);
 99}
 100
 101RGBA32 makeUnPremultipliedRGBA(int r, int g, int b, int a)
 102{
 103 return makeRGBA(unpremultipliedChannel(r, a), unpremultipliedChannel(g, a), unpremultipliedChannel(b, a), a);
 104}
 105
62106static int colorFloatToRGBAByte(float f)
63107{
64108 // We use lroundf and 255 instead of nextafterf(256, 0) to match CG's rounding

Source/WebCore/platform/graphics/Color.h

@@typedef unsigned RGBA32; // Deprecated: Type for an RGBA quadruplet. Use RGBA cl
5454
5555WEBCORE_EXPORT RGBA32 makeRGB(int r, int g, int b);
5656WEBCORE_EXPORT RGBA32 makeRGBA(int r, int g, int b, int a);
 57WEBCORE_EXPORT RGBA32 makePremultipliedRGBA(int r, int g, int b, int a);
 58WEBCORE_EXPORT RGBA32 makeUnPremultipliedRGBA(int r, int g, int b, int a);
5759
5860WEBCORE_EXPORT RGBA32 colorWithOverrideAlpha(RGBA32 color, float overrideAlpha);
5961WEBCORE_EXPORT RGBA32 colorWithOverrideAlpha(RGBA32 color, Optional<float> overrideAlpha);

Source/WebCore/platform/graphics/Image.h

@@public:
137137
138138 enum TileRule { StretchTile, RoundTile, SpaceTile, RepeatTile };
139139
 140 virtual NativeImagePtr nativeImage() { return nullptr; }
 141 virtual NativeImagePtr nativeImageOfSize(const IntSize&) { return nullptr; }
140142 virtual NativeImagePtr nativeImageForCurrentFrame() { return nullptr; }
141143 virtual ImageOrientation orientationForCurrentFrame() { return ImageOrientation(); }
 144 virtual Vector<NativeImagePtr> framesNativeImages() { return { }; }
142145
143146 // Accessors for native image formats.
144147

@@public:
150153 virtual CFDataRef getTIFFRepresentation() { return nullptr; }
151154#endif
152155
153 #if USE(CG)
154  virtual CGImageRef getCGImageRef() { return nullptr; }
155  virtual CGImageRef getFirstCGImageRefOfSize(const IntSize&) { return nullptr; }
156  virtual RetainPtr<CFArrayRef> getCGImageArray() { return nullptr; }
157 #endif
158 
159156#if PLATFORM(WIN)
160157 virtual bool getHBITMAP(HBITMAP) { return false; }
161158 virtual bool getHBITMAPOfSize(HBITMAP, const IntSize*) { return false; }

@@public:
179176#if !ASSERT_DISABLED
180177 virtual bool notSolidColor() { return true; }
181178#endif
 179
 180 virtual void layoutIfNeeded() { }
182181
183182 virtual void dump(TextStream&) const;
184183

Source/WebCore/platform/graphics/ImageFrameData.cpp

 1/*
 2 * Copyright (C) 2016 Apple Inc. All rights reserved.
 3 *
 4 * Redistribution and use in source and binary forms, with or without
 5 * modification, are permitted provided that the following conditions
 6 * are met:
 7 * 1. Redistributions of source code must retain the above copyright
 8 * notice, this list of conditions and the following disclaimer.
 9 * 2. Redistributions in binary form must reproduce the above copyright
 10 * notice, this list of conditions and the following disclaimer in the
 11 * documentation and/or other materials provided with the distribution.
 12 *
 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 24 */
 25
 26#include "config.h"
 27#include "ImageFrameData.h"
 28
 29#include "Color.h"
 30
 31#if USE(CG)
 32#include "ImageDecoderCG.h"
 33#else
 34#include "ImageDecoder.h"
 35#endif
 36
 37#include "PlatformImage.h"
 38
 39namespace WebCore {
 40
 41ImageFrameData::ImageFrameData()
 42{
 43}
 44
 45ImageFrameData::ImageFrameData(NativeImagePtr&& image)
 46 : m_status(DecodingStatus::Complete)
 47 , m_image(WTFMove(image))
 48{
 49 m_size = PlatformImage(m_image).size();
 50 m_hasAlpha = PlatformImage(m_image).hasAlpha();
 51}
 52
 53ImageFrameData::ImageFrameData(ImageDecoder& decoder, size_t index, SubsamplingLevel subsamplingLevel, Caching frameCaching)
 54{
 55 ASSERT(frameCaching == Caching::Metadata || frameCaching == Caching::MetadataAndImage);
 56
 57 if (frameCaching == Caching::Image || frameCaching == Caching::MetadataAndImage) {
 58 m_image = decoder.createFrameImageAtIndex(index, subsamplingLevel);
 59 m_subsamplingLevel = subsamplingLevel;
 60 }
 61
 62 if (frameCaching == Caching::Metadata || frameCaching == Caching::MetadataAndImage) {
 63 m_orientation = decoder.orientationAtIndex(index);
 64 m_status = decoder.frameIsCompleteAtIndex(index) ? DecodingStatus::Complete : DecodingStatus::Partial;
 65
 66 if (decoder.repetitionCount() != cAnimationNone)
 67 m_duration = decoder.frameDurationAtIndex(index);
 68
 69 m_hasAlpha = decoder.frameHasAlphaAtIndex(index);
 70 m_size = decoder.frameSizeAtIndex(index, subsamplingLevel);
 71 }
 72}
 73
 74ImageFrameData::~ImageFrameData()
 75{
 76 clearSubImages();
 77}
 78
 79ImageFrameData& ImageFrameData::operator=(const ImageFrameData& other)
 80{
 81 if (this == &other)
 82 return *this;
 83
 84 m_status = other.m_status;
 85 m_size = other.m_size;
 86 m_image = other.m_image;
 87
 88 m_pixels = other.pixels() ? BitmapPixels::create(*other.pixels()) : nullptr;
 89
 90 m_orientation = other.m_orientation;
 91 m_subsamplingLevel = other.m_subsamplingLevel;
 92 m_duration = other.m_duration;
 93 m_hasAlpha = other.m_hasAlpha;
 94 return *this;
 95}
 96
 97void ImageFrameData::clearSubImages()
 98{
 99 if (!m_image)
 100 return;
 101
 102 PlatformImage(m_image).clearSubImages();
 103}
 104
 105unsigned ImageFrameData::clear(Caching frameCaching)
 106{
 107 ASSERT(frameCaching == Caching::Empty || frameCaching == Caching::Metadata);
 108
 109 unsigned frameBytes = this->frameBytes();
 110
 111 clearSubImages();
 112
 113 if (frameCaching == Caching::Empty)
 114 *this = ImageFrameData();
 115 else
 116 m_image = nullptr;
 117
 118 return frameBytes;
 119}
 120
 121Color ImageFrameData::singlePixelSolidColor() const
 122{
 123 if (!hasImage() || m_size != IntSize(1, 1))
 124 return Color();
 125
 126 return PlatformImage(m_image).singlePixelSolidColor();
 127}
 128
 129bool ImageFrameData::isAlmostSolidColor() const
 130{
 131 if (!hasImage())
 132 return false;
 133
 134 return PlatformImage(m_image).isAlmostSolidColor();
 135}
 136
 137}

Source/WebCore/platform/graphics/ImageFrameData.h

 1/*
 2 * Copyright (C) 2016 Apple Inc. All rights reserved.
 3 *
 4 * Redistribution and use in source and binary forms, with or without
 5 * modification, are permitted provided that the following conditions
 6 * are met:
 7 * 1. Redistributions of source code must retain the above copyright
 8 * notice, this list of conditions and the following disclaimer.
 9 * 2. Redistributions in binary form must reproduce the above copyright
 10 * notice, this list of conditions and the following disclaimer in the
 11 * documentation and/or other materials provided with the distribution.
 12 *
 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 24 */
 25
 26#pragma once
 27
 28#include "BitmapPixels.h"
 29#include "ImageOrientation.h"
 30#include "IntSize.h"
 31#include "NativeImagePtr.h"
 32
 33namespace WebCore {
 34
 35class Color;
 36class ImageDecoder;
 37
 38// SubsamplingLevel. 0 is no subsampling, 1 is half dimensions on each axis etc.
 39using SubsamplingLevel = uint8_t;
 40
 41enum : SubsamplingLevel {
 42 MinSubsamplingLevel = 0,
 43 MaxSubsamplingLevel = 3,
 44 DefaultSubsamplingLevel = MinSubsamplingLevel
 45};
 46
 47class ImageFrameData {
 48 friend class ImageDecoder;
 49public:
 50 enum class Caching { Empty, Metadata, Image, MetadataAndImage };
 51 enum class DecodingStatus { Empty, Partial, Complete };
 52
 53 ImageFrameData();
 54 ImageFrameData(NativeImagePtr&&);
 55 ImageFrameData(ImageDecoder&, size_t index, SubsamplingLevel = DefaultSubsamplingLevel, Caching = Caching::MetadataAndImage);
 56 ImageFrameData(const ImageFrameData& other) { operator=(other); }
 57
 58 ~ImageFrameData();
 59
 60 ImageFrameData& operator=(const ImageFrameData& other);
 61
 62 unsigned clear(Caching);
 63 Color singlePixelSolidColor() const;
 64 bool isAlmostSolidColor() const;
 65
 66 DecodingStatus status() const { return m_status; }
 67 bool isComplete() const { return m_status == DecodingStatus::Complete; }
 68 IntSize size() const { return hasPixels() ? pixels()->size() : m_size; }
 69 unsigned frameBytes() const { return hasImage() ? m_size.area() * sizeof(RGBA32) : 0; }
 70 NativeImagePtr image() const { return m_image; }
 71 BitmapPixels* pixels() const { return m_pixels ? m_pixels.get() : nullptr; }
 72
 73 ImageOrientation orientation() const { return m_orientation; }
 74 SubsamplingLevel subsamplingLevel() const { return m_subsamplingLevel; }
 75 float duration() const { return m_duration; }
 76
 77 bool hasAlpha() const { return m_hasAlpha; }
 78 bool hasImage() const { return m_image; }
 79 bool hasMetadata() const { return !m_size.isEmpty(); }
 80 bool hasPixels() const { return pixels(); }
 81
 82private:
 83 void clearSubImages();
 84
 85 void setStatus(DecodingStatus status) { m_status = status; }
 86 void setOrientation(ImageOrientation orientation) { m_orientation = orientation; };
 87 void setDuration(unsigned duration) { m_duration = duration; }
 88 void setHasAlpha(bool hasAlpha) { m_hasAlpha = hasAlpha; }
 89
 90 DecodingStatus m_status { DecodingStatus::Empty };
 91 IntSize m_size;
 92 NativeImagePtr m_image;
 93 std::unique_ptr<BitmapPixels> m_pixels;
 94
 95 ImageOrientation m_orientation { DefaultImageOrientation };
 96 SubsamplingLevel m_subsamplingLevel { 0 };
 97 float m_duration { 0 };
 98 bool m_hasAlpha { true };
 99};
 100
 101}

Source/WebCore/platform/graphics/ImageSource.cpp

@@NativeImagePtr ImageSource::createFrameImageAtIndex(size_t index, SubsamplingLev
224224 return initialized() ? m_decoder->createFrameImageAtIndex(index, subsamplingLevel) : nullptr;
225225}
226226
 227ImageFrameData ImageSource::createFrameDataAtIndex(size_t index, SubsamplingLevel subsamplingLevel, ImageFrameData::Caching caching)
 228{
 229 return initialized() ? ImageFrameData(*m_decoder, index, subsamplingLevel, caching) : ImageFrameData();
 230}
 231
227232void ImageSource::dump(TextStream& ts) const
228233{
229234 if (m_allowSubsampling)

Source/WebCore/platform/graphics/ImageSource.h

2727#ifndef ImageSource_h
2828#define ImageSource_h
2929
 30#include "ImageFrameData.h"
3031#include "ImageOrientation.h"
3132#include "IntPoint.h"
3233#include "NativeImagePtr.h"

@@const int cAnimationLoopOnce = 0;
6364const int cAnimationLoopInfinite = -1;
6465const int cAnimationNone = -2;
6566
66 // SubsamplingLevel. 0 is no subsampling, 1 is half dimensions on each axis etc.
67 typedef short SubsamplingLevel;
68 
6967class ImageSource {
7068 WTF_MAKE_NONCOPYABLE(ImageSource);
7169 friend class BitmapImage;

@@public:
132130 bool allowSubsamplingOfFrameAtIndex(size_t) const;
133131
134132 // Size of optionally subsampled frame.
135  IntSize frameSizeAtIndex(size_t, SubsamplingLevel = 0, RespectImageOrientationEnum = DoNotRespectImageOrientation) const;
 133 IntSize frameSizeAtIndex(size_t, SubsamplingLevel = DefaultSubsamplingLevel, RespectImageOrientationEnum = DoNotRespectImageOrientation) const;
136134
137135 // Return the number of bytes in the decoded frame. If the frame is not yet
138136 // decoded then return 0.
139  unsigned frameBytesAtIndex(size_t, SubsamplingLevel = 0) const;
 137 unsigned frameBytesAtIndex(size_t, SubsamplingLevel = DefaultSubsamplingLevel) const;
140138
141139 float frameDurationAtIndex(size_t);
142140 ImageOrientation orientationAtIndex(size_t) const; // EXIF image orientation
143141
144142 // Callers should not call this after calling clear() with a higher index;
145143 // see comments on clear() above.
146  NativeImagePtr createFrameImageAtIndex(size_t, SubsamplingLevel = 0);
 144 NativeImagePtr createFrameImageAtIndex(size_t, SubsamplingLevel = DefaultSubsamplingLevel);
 145 ImageFrameData createFrameDataAtIndex(size_t, SubsamplingLevel = DefaultSubsamplingLevel, ImageFrameData::Caching = ImageFrameData::Caching::MetadataAndImage);
147146
148147private:
149148 void clearFrameBufferCache(size_t);

Source/WebCore/platform/graphics/PlatformImage.h

 1/*
 2 * Copyright (C) 2016 Apple Inc. All rights reserved.
 3 *
 4 * Redistribution and use in source and binary forms, with or without
 5 * modification, are permitted provided that the following conditions
 6 * are met:
 7 * 1. Redistributions of source code must retain the above copyright
 8 * notice, this list of conditions and the following disclaimer.
 9 * 2. Redistributions in binary form must reproduce the above copyright
 10 * notice, this list of conditions and the following disclaimer in the
 11 * documentation and/or other materials provided with the distribution.
 12 *
 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 24 */
 25
 26#pragma once
 27
 28#include "GraphicsTypes.h"
 29#include "ImageOrientation.h"
 30#include "NativeImagePtr.h"
 31
 32namespace WebCore {
 33
 34class Color;
 35class FloatRect;
 36class IntSize;
 37class GraphicsContext;
 38
 39class PlatformImage {
 40public:
 41 PlatformImage(const NativeImagePtr& image)
 42 : m_image(image)
 43 {
 44 }
 45
 46 bool isNil() const { return !m_image; }
 47 void clearSubImages();
 48
 49 IntSize size() const;
 50 bool hasAlpha() const;
 51 Color singlePixelSolidColor() const;
 52 bool isAlmostSolidColor() const;
 53 void draw(GraphicsContext&, const FloatRect& destRect, const FloatRect& srcRect, const IntSize& srcSize, CompositeOperator, BlendMode, const ImageOrientation&) const;
 54
 55 static float subsamplingScale(GraphicsContext&, const FloatRect& destRect, const FloatRect& srcRect);
 56
 57private:
 58#if USE(CG)
 59 CGImageRef cgImageRef() const { return m_image ? m_image.get() : nullptr; }
 60#endif
 61 NativeImagePtr m_image;
 62};
 63
 64}

Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.mm

@@void MediaPlayerPrivateMediaStreamAVFObjC::updateDisplayMode()
212212 continue;
213213 }
214214
215  m_pausedImage = image->getCGImageRef();
 215 m_pausedImage = image->nativeImageForCurrentFrame();
216216 if (!m_pausedImage) {
217217 m_displayMode = PaintItBlack;
218218 continue;

Source/WebCore/platform/graphics/cairo/BitmapImageCairo.cpp

1 /*
2  * Copyright (C) 2004, 2005, 2006 Apple Inc. All rights reserved.
3  * Copyright (C) 2007 Alp Toker <alp@atoker.com>
4  * Copyright (C) 2009 Dirk Schulze <krit@webkit.org>
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
16  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
19  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
23  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #include "config.h"
29 #include "BitmapImage.h"
30 
31 #if USE(CAIRO)
32 
33 #include "CairoUtilities.h"
34 #include "ImageObserver.h"
35 #include "PlatformContextCairo.h"
36 #include "Timer.h"
37 #include <cairo.h>
38 
39 namespace WebCore {
40 
41 namespace NativeImage {
42 
43 IntSize size(const RefPtr<cairo_surface_t>& image)
44 {
45  return cairoSurfaceSize(image.get());
46 }
47 
48 bool hasAlpha(const RefPtr<cairo_surface_t>& image)
49 {
50  return cairo_surface_get_content(image.get()) != CAIRO_CONTENT_COLOR;
51 }
52 
53 Color singlePixelSolidColor(const RefPtr<cairo_surface_t>& image)
54 {
55  ASSERT(image);
56 
57  if (NativeImage::size(image) != IntSize(1, 1))
58  return Color();
59 
60  if (cairo_surface_get_type(image.get()) != CAIRO_SURFACE_TYPE_IMAGE)
61  return Color();
62 
63  RGBA32* pixel = reinterpret_cast_ptr<RGBA32*>(cairo_image_surface_get_data(image.get()));
64  return colorFromPremultipliedARGB(*pixel);
65 }
66 
67 }
68 
69 void BitmapImage::draw(GraphicsContext& context, const FloatRect& dst, const FloatRect& src, CompositeOperator op,
70  BlendMode blendMode, ImageOrientationDescription description)
71 {
72  if (!dst.width() || !dst.height() || !src.width() || !src.height())
73  return;
74 
75  startAnimation();
76 
77  auto surface = frameImageAtIndex(m_currentFrame);
78  if (!surface) // If it's too early we won't have an image yet.
79  return;
80 
81  Color color = singlePixelSolidColor();
82  if (color.isValid()) {
83  fillWithSolidColor(context, dst, color, op);
84  return;
85  }
86 
87  context.save();
88 
89  // Set the compositing operation.
90  if (op == CompositeSourceOver && blendMode == BlendModeNormal && !frameHasAlphaAtIndex(m_currentFrame))
91  context.setCompositeOperation(CompositeCopy);
92  else
93  context.setCompositeOperation(op, blendMode);
94 
95 #if ENABLE(IMAGE_DECODER_DOWN_SAMPLING)
96  IntSize scaledSize = cairoSurfaceSize(surface.get());
97  FloatRect adjustedSrcRect = adjustSourceRectForDownSampling(src, scaledSize);
98 #else
99  FloatRect adjustedSrcRect(src);
100 #endif
101 
102  ImageOrientation frameOrientation(description.imageOrientation());
103  if (description.respectImageOrientation() == RespectImageOrientation)
104  frameOrientation = frameOrientationAtIndex(m_currentFrame);
105 
106  FloatRect dstRect = dst;
107 
108  if (frameOrientation != DefaultImageOrientation) {
109  // ImageOrientation expects the origin to be at (0, 0).
110  context.translate(dstRect.x(), dstRect.y());
111  dstRect.setLocation(FloatPoint());
112  context.concatCTM(frameOrientation.transformFromDefault(dstRect.size()));
113  if (frameOrientation.usesWidthAsHeight()) {
114  // The destination rectangle will have it's width and height already reversed for the orientation of
115  // the image, as it was needed for page layout, so we need to reverse it back here.
116  dstRect = FloatRect(dstRect.x(), dstRect.y(), dstRect.height(), dstRect.width());
117  }
118  }
119 
120  context.platformContext()->drawSurfaceToContext(surface.get(), dstRect, adjustedSrcRect, context);
121 
122  context.restore();
123 
124  if (imageObserver())
125  imageObserver()->didDraw(this);
126 }
127 
128 bool FrameData::clear(bool clearMetadata)
129 {
130  if (clearMetadata)
131  m_haveMetadata = false;
132 
133  if (m_image) {
134  m_image = nullptr;
135  return true;
136  }
137  return false;
138 }
139 
140 } // namespace WebCore
141 
142 #endif // USE(CAIRO)

Source/WebCore/platform/graphics/cairo/PlatformImageCairo.cpp

 1/*
 2 * Copyright (C) 2016 Apple Inc. All rights reserved.
 3 *
 4 * Redistribution and use in source and binary forms, with or without
 5 * modification, are permitted provided that the following conditions
 6 * are met:
 7 * 1. Redistributions of source code must retain the above copyright
 8 * notice, this list of conditions and the following disclaimer.
 9 * 2. Redistributions in binary form must reproduce the above copyright
 10 * notice, this list of conditions and the following disclaimer in the
 11 * documentation and/or other materials provided with the distribution.
 12 *
 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 24 */
 25
 26#include "config.h"
 27#include "PlatformImage.h"
 28
 29#if USE(CAIRO)
 30
 31#include "CairoUtilities.h"
 32#include "PlatformContextCairo.h"
 33#include <cairo.h>
 34
 35namespace WebCore {
 36
 37void PlatformImage::clearSubImages()
 38{
 39}
 40
 41IntSize PlatformImage::size() const
 42{
 43 return isNil() ? IntSize() : cairoSurfaceSize(m_image.get());
 44}
 45
 46bool PlatformImage::hasAlpha() const
 47{
 48 return isNil() || cairo_surface_get_content(m_image.get()) != CAIRO_CONTENT_COLOR;
 49}
 50
 51Color PlatformImage::singlePixelSolidColor() const
 52{
 53 if (isNil() || size() != IntSize(1, 1))
 54 return Color();
 55
 56 if (cairo_surface_get_type(m_image.get()) != CAIRO_SURFACE_TYPE_IMAGE)
 57 return Color();
 58
 59 RGBA32* pixel = reinterpret_cast_ptr<RGBA32*>(cairo_image_surface_get_data(m_image.get()));
 60 return colorFromPremultipliedARGB(*pixel);
 61}
 62
 63bool PlatformImage::isAlmostSolidColor() const
 64{
 65 return false;
 66}
 67
 68float PlatformImage::subsamplingScale(GraphicsContext&, const FloatRect&, const FloatRect&)
 69{
 70 return 1;
 71}
 72
 73void PlatformImage::draw(GraphicsContext& context, const FloatRect& destRect, const FloatRect& srcRect, const IntSize&, CompositeOperator op, BlendMode mode, const ImageOrientation& orientation) const
 74{
 75 context.save();
 76
 77 // Set the compositing operation.
 78 if (op == CompositeSourceOver && mode == BlendModeNormal && !hasAlpha())
 79 context.setCompositeOperation(CompositeCopy);
 80 else
 81 context.setCompositeOperation(op, mode);
 82
 83#if ENABLE(IMAGE_DECODER_DOWN_SAMPLING)
 84 IntSize scaledSize = cairoSurfaceSize(m_image.get());
 85 FloatRect adjustedSrcRect = adjustSourceRectForDownSampling(srcRect, scaledSize);
 86#else
 87 FloatRect adjustedSrcRect(srcRect);
 88#endif
 89
 90 FloatRect adjustedDestRect = destRect;
 91
 92 if (orientation != DefaultImageOrientation) {
 93 // ImageOrientation expects the origin to be at (0, 0).
 94 context.translate(destRect.x(), destRect.y());
 95 adjustedDestRect.setLocation(FloatPoint());
 96 context.concatCTM(orientation.transformFromDefault(adjustedDestRect.size()));
 97 if (orientation.usesWidthAsHeight()) {
 98 // The destination rectangle will have it's width and height already reversed for the orientation of
 99 // the image, as it was needed for page layout, so we need to reverse it back here.
 100 adjustedDestRect.setSize(adjustedDestRect.size().transposedSize());
 101 }
 102 }
 103
 104 context.platformContext()->drawSurfaceToContext(m_image.get(), adjustedDestRect, adjustedSrcRect, context);
 105
 106 context.restore();
 107}
 108
 109} // namespace WebCore
 110
 111#endif // USE(CAIRO)

Source/WebCore/platform/graphics/cg/BitmapImageCG.cpp

1 /*
2  * Copyright (C) 2004, 2005, 2006 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */
25 
26 #include "config.h"
27 #include "BitmapImage.h"
28 
29 #if USE(CG)
30 
31 #include "CoreGraphicsSPI.h"
32 #include "FloatConversion.h"
33 #include "GeometryUtilities.h"
34 #include "GraphicsContextCG.h"
35 #include "ImageObserver.h"
36 #include "SubimageCacheWithTimer.h"
37 #include <wtf/RetainPtr.h>
38 
39 #if USE(APPKIT)
40 #include <ApplicationServices/ApplicationServices.h>
41 #endif
42 
43 #if PLATFORM(COCOA)
44 #include "WebCoreSystemInterface.h"
45 #endif
46 
47 #if PLATFORM(WIN)
48 #include <WebKitSystemInterface/WebKitSystemInterface.h>
49 #endif
50 
51 namespace WebCore {
52 
53 namespace NativeImage {
54 
55 IntSize size(const RetainPtr<CGImageRef>& image)
56 {
57  ASSERT(image);
58  return IntSize(CGImageGetWidth(image.get()), CGImageGetHeight(image.get()));
59 }
60 
61 bool hasAlpha(const RetainPtr<CGImageRef>&)
62 {
63  // FIXME: Answer correctly the question: does the CGImageRef have alpha channnel?
64  return true;
65 }
66 
67 Color singlePixelSolidColor(const RetainPtr<CGImageRef>& image)
68 {
69  ASSERT(image);
70 
71  if (NativeImage::size(image) != IntSize(1, 1))
72  return Color();
73 
74  unsigned char pixel[4]; // RGBA
75  auto bitmapContext = adoptCF(CGBitmapContextCreate(pixel, 1, 1, 8, sizeof(pixel), sRGBColorSpaceRef(),
76  kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big));
77 
78  if (!bitmapContext)
79  return Color();
80 
81  CGContextSetBlendMode(bitmapContext.get(), kCGBlendModeCopy);
82  CGContextDrawImage(bitmapContext.get(), CGRectMake(0, 0, 1, 1), image.get());
83 
84  if (!pixel[3])
85  return Color(0, 0, 0, 0);
86 
87  return Color(pixel[0] * 255 / pixel[3], pixel[1] * 255 / pixel[3], pixel[2] * 255 / pixel[3], pixel[3]);
88 }
89 
90 }
91 
92 bool FrameData::clear(bool clearMetadata)
93 {
94  if (clearMetadata)
95  m_haveMetadata = false;
96 
97  m_subsamplingLevel = 0;
98 
99  if (m_image) {
100 #if CACHE_SUBIMAGES
101  subimageCache().clearImage(m_image.get());
102 #endif
103  m_image = nullptr;
104  return true;
105  }
106  return false;
107 }
108 
109 CGImageRef BitmapImage::getCGImageRef()
110 {
111  return frameImageAtIndex(0).get();
112 }
113 
114 CGImageRef BitmapImage::getFirstCGImageRefOfSize(const IntSize& size)
115 {
116  size_t count = frameCount();
117  for (size_t i = 0; i < count; ++i) {
118  CGImageRef cgImage = frameImageAtIndex(i).get();
119  if (cgImage && IntSize(CGImageGetWidth(cgImage), CGImageGetHeight(cgImage)) == size)
120  return cgImage;
121  }
122 
123  // Fallback to the default CGImageRef if we can't find the right size
124  return getCGImageRef();
125 }
126 
127 RetainPtr<CFArrayRef> BitmapImage::getCGImageArray()
128 {
129  size_t count = frameCount();
130  if (!count)
131  return nullptr;
132 
133  CFMutableArrayRef array = CFArrayCreateMutable(NULL, count, &kCFTypeArrayCallBacks);
134  for (size_t i = 0; i < count; ++i) {
135  if (CGImageRef currFrame = frameImageAtIndex(i).get())
136  CFArrayAppendValue(array, currFrame);
137  }
138  return adoptCF(array);
139 }
140 
141 void BitmapImage::draw(GraphicsContext& ctxt, const FloatRect& destRect, const FloatRect& srcRect, CompositeOperator compositeOp, BlendMode blendMode, ImageOrientationDescription description)
142 {
143 #if PLATFORM(IOS)
144  startAnimation(DoNotCatchUp);
145 #else
146  startAnimation();
147 #endif
148 
149  RetainPtr<CGImageRef> image;
150  // Never use subsampled images for drawing into PDF contexts.
151  if (wkCGContextIsPDFContext(ctxt.platformContext()))
152  image = copyUnscaledFrameImageAtIndex(m_currentFrame);
153  else {
154  CGRect transformedDestinationRect = CGRectApplyAffineTransform(destRect, CGContextGetCTM(ctxt.platformContext()));
155  float subsamplingScale = std::min<float>(1, std::max(transformedDestinationRect.size.width / srcRect.width(), transformedDestinationRect.size.height / srcRect.height()));
156 
157  image = frameImageAtIndex(m_currentFrame, subsamplingScale);
158  }
159 
160  if (!image) // If it's too early we won't have an image yet.
161  return;
162 
163  Color color = singlePixelSolidColor();
164  if (color.isValid()) {
165  fillWithSolidColor(ctxt, destRect, color, compositeOp);
166  return;
167  }
168 
169  // Subsampling may have given us an image that is smaller than size().
170  IntSize imageSize(CGImageGetWidth(image.get()), CGImageGetHeight(image.get()));
171 
172  // srcRect is in the coordinates of the unsubsampled image, so we have to map it to the subsampled image.
173  FloatRect scaledSrcRect = srcRect;
174  if (imageSize != m_size) {
175  FloatRect originalImageBounds(FloatPoint(), m_size);
176  FloatRect subsampledImageBounds(FloatPoint(), imageSize);
177  scaledSrcRect = mapRect(srcRect, originalImageBounds, subsampledImageBounds);
178  }
179 
180  ImageOrientation orientation;
181  if (description.respectImageOrientation() == RespectImageOrientation)
182  orientation = frameOrientationAtIndex(m_currentFrame);
183 
184  ctxt.drawNativeImage(image, imageSize, destRect, scaledSrcRect, compositeOp, blendMode, orientation);
185 
186  if (imageObserver())
187  imageObserver()->didDraw(this);
188 }
189 
190 RetainPtr<CGImageRef> BitmapImage::copyUnscaledFrameImageAtIndex(size_t index)
191 {
192  if (index >= frameCount())
193  return nullptr;
194 
195  if (index >= m_frames.size() || !m_frames[index].m_image)
196  cacheFrame(index, 0);
197 
198  if (!m_frames[index].m_subsamplingLevel)
199  return m_frames[index].m_image;
200 
201  return m_source.createFrameImageAtIndex(index);
202 }
203 
204 }
205 
206 #endif // USE(CG)

Source/WebCore/platform/graphics/cg/PatternCG.cpp

@@CGPatternRef Pattern::createPlatformPattern(const AffineTransform& userSpaceTran
7272 // If we're repeating in both directions, we can use image-backed patterns
7373 // instead of custom patterns, and avoid tiling-edge pixel cracks.
7474 if (m_repeatX && m_repeatY)
75  return wkCGPatternCreateWithImageAndTransform(tileImage()->getCGImageRef(), patternTransform, wkPatternTilingConstantSpacing);
 75 return wkCGPatternCreateWithImageAndTransform(tileImage()->nativeImage().get(), patternTransform, wkPatternTilingConstantSpacing);
7676
7777 // If FLT_MAX should also be used for xStep or yStep, nothing is rendered. Using fractions of FLT_MAX also
7878 // result in nothing being rendered.

@@CGPatternRef Pattern::createPlatformPattern(const AffineTransform& userSpaceTran
8383 CGFloat yStep = m_repeatY ? tileRect.height() : (1 << 22);
8484
8585 // The pattern will release the CGImageRef when it's done rendering in patternReleaseCallback
86  CGImageRef platformImage = CGImageRetain(tileImage()->getCGImageRef());
 86 CGImageRef platformImage = tileImage()->nativeImage().leakRef();
8787
8888 const CGPatternCallbacks patternCallbacks = { 0, patternCallback, patternReleaseCallback };
8989 return CGPatternCreate(platformImage, tileRect, patternTransform, xStep, yStep, kCGPatternTilingConstantSpacing, TRUE, &patternCallbacks);

Source/WebCore/platform/graphics/cg/PlatformImageCG.cpp

 1/*
 2 * Copyright (C) 2016 Apple Inc. All rights reserved.
 3 *
 4 * Redistribution and use in source and binary forms, with or without
 5 * modification, are permitted provided that the following conditions
 6 * are met:
 7 * 1. Redistributions of source code must retain the above copyright
 8 * notice, this list of conditions and the following disclaimer.
 9 * 2. Redistributions in binary form must reproduce the above copyright
 10 * notice, this list of conditions and the following disclaimer in the
 11 * documentation and/or other materials provided with the distribution.
 12 *
 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 24 */
 25
 26#include "config.h"
 27#include "PlatformImage.h"
 28
 29#if USE(CG)
 30
 31#include "Color.h"
 32#include "CoreGraphicsSPI.h"
 33#include "FloatRect.h"
 34#include "GeometryUtilities.h"
 35#include "GraphicsContextCG.h"
 36#include "IntSize.h"
 37#include "SubimageCacheWithTimer.h"
 38
 39#if PLATFORM(WIN)
 40#include <WebKitSystemInterface/WebKitSystemInterface.h>
 41#endif
 42
 43namespace WebCore {
 44
 45void PlatformImage::clearSubImages()
 46{
 47#if CACHE_SUBIMAGES
 48 if (!isNil())
 49 subimageCache().clearImage(cgImageRef());
 50#endif
 51}
 52
 53IntSize PlatformImage::size() const
 54{
 55 return isNil() ? IntSize() : IntSize(CGImageGetWidth(cgImageRef()), CGImageGetHeight(cgImageRef()));
 56}
 57
 58bool PlatformImage::hasAlpha() const
 59{
 60 // FIXME: Answer correctly the question: does the CGImageRef have alpha channnel?
 61 return true;
 62}
 63
 64Color PlatformImage::singlePixelSolidColor() const
 65{
 66 if (isNil() || size() != IntSize(1, 1))
 67 return Color();
 68
 69 unsigned char pixel[4]; // RGBA
 70 auto bitmapContext = adoptCF(CGBitmapContextCreate(pixel, 1, 1, 8, sizeof(pixel), sRGBColorSpaceRef(),
 71 kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big));
 72
 73 if (!bitmapContext)
 74 return Color();
 75
 76 CGContextSetBlendMode(bitmapContext.get(), kCGBlendModeCopy);
 77 CGContextDrawImage(bitmapContext.get(), CGRectMake(0, 0, 1, 1), cgImageRef());
 78
 79 if (!pixel[3])
 80 return Color(0, 0, 0, 0);
 81
 82 return Color(pixel[0] * 255 / pixel[3], pixel[1] * 255 / pixel[3], pixel[2] * 255 / pixel[3], pixel[3]);
 83}
 84
 85bool PlatformImage::isAlmostSolidColor() const
 86{
 87 CGImageRef image = cgImageRef();
 88 ASSERT(CGImageGetBitsPerComponent(image) == 8);
 89
 90 CGBitmapInfo imageInfo = CGImageGetBitmapInfo(image);
 91 if (!(imageInfo & kCGBitmapByteOrder32Little) || (imageInfo & kCGBitmapAlphaInfoMask) != kCGImageAlphaPremultipliedFirst) {
 92 // FIXME: Consider being able to handle other pixel formats.
 93 ASSERT_NOT_REACHED();
 94 return false;
 95 }
 96
 97 size_t width = CGImageGetWidth(image);
 98 size_t height = CGImageGetHeight(image);
 99 size_t bytesPerRow = CGImageGetBytesPerRow(image);
 100
 101 RetainPtr<CFDataRef> provider = adoptCF(CGDataProviderCopyData(CGImageGetDataProvider(image)));
 102 const UInt8* data = CFDataGetBytePtr(provider.get());
 103
 104 // Overlay a grid of sampling dots on top of a grayscale version of the image.
 105 // For the interior points, calculate the difference in luminance among the sample point
 106 // and its surrounds points, scaled by transparency.
 107 const unsigned sampleRows = 7;
 108 const unsigned sampleCols = 7;
 109 // FIXME: Refine the proper number of samples, and accommodate different aspect ratios.
 110 if (width < sampleCols || height < sampleRows)
 111 return false;
 112
 113 // Ensure that the last row/column land on the image perimeter.
 114 const float strideWidth = static_cast<float>(width - 1) / (sampleCols - 1);
 115 const float strideHeight = static_cast<float>(height - 1) / (sampleRows - 1);
 116 float samples[sampleRows][sampleCols];
 117
 118 // Find the luminance of the sample points.
 119 float y = 0;
 120 const UInt8* row = data;
 121 for (unsigned i = 0; i < sampleRows; ++i) {
 122 float x = 0;
 123 for (unsigned j = 0; j < sampleCols; ++j) {
 124 const UInt8* p0 = row + (static_cast<int>(x + .5)) * 4;
 125 // R G B A
 126 samples[i][j] = (0.2125 * *p0 + 0.7154 * *(p0+1) + 0.0721 * *(p0+2)) * *(p0+3) / 255;
 127 x += strideWidth;
 128 }
 129 y += strideHeight;
 130 row = data + (static_cast<int>(y + .5)) * bytesPerRow;
 131 }
 132
 133 // Determine the image score.
 134 float accumScore = 0;
 135 for (unsigned i = 1; i < sampleRows - 1; ++i) {
 136 for (unsigned j = 1; j < sampleCols - 1; ++j) {
 137 float diff = samples[i - 1][j] + samples[i + 1][j] + samples[i][j - 1] + samples[i][j + 1] - 4 * samples[i][j];
 138 accumScore += diff * diff;
 139 }
 140 }
 141
 142 // The score for a given sample can be within the range of 0 and 255^2.
 143 return accumScore < 2500 * (sampleRows - 2) * (sampleCols - 2);
 144}
 145
 146float PlatformImage::subsamplingScale(GraphicsContext& context, const FloatRect& destRect, const FloatRect& srcRect)
 147{
 148 // Never use subsampled images for drawing into PDF contexts.
 149 if (wkCGContextIsPDFContext(context.platformContext()))
 150 return 1;
 151
 152 CGRect transformedDestinationRect = CGRectApplyAffineTransform(destRect, CGContextGetCTM(context.platformContext()));
 153 return std::min<float>(1, std::max(transformedDestinationRect.size.width / srcRect.width(), transformedDestinationRect.size.height / srcRect.height()));
 154}
 155
 156void PlatformImage::draw(GraphicsContext& context, const FloatRect& destRect, const FloatRect& srcRect, const IntSize& srcSize, CompositeOperator op, BlendMode mode, const ImageOrientation& orientation) const
 157{
 158 // Subsampling may have given us an image that is smaller than size().
 159 IntSize subsampledImageSize = size();
 160
 161 // srcRect is in the coordinates of the unsubsampled image, so we have to map it to the subsampled image.
 162 FloatRect adjustedSrcRect = srcRect;
 163 if (subsampledImageSize != srcSize)
 164 adjustedSrcRect = mapRect(srcRect, FloatRect({ }, srcSize), FloatRect({ }, subsampledImageSize));
 165
 166 context.drawNativeImage(m_image, subsampledImageSize, destRect, adjustedSrcRect, op, mode, orientation);
 167}
 168
 169}
 170
 171#endif // USE(CG)

Source/WebCore/platform/graphics/cocoa/TextTrackRepresentationCocoa.mm

@@TextTrackRepresentationCocoa::~TextTrackRepresentationCocoa()
129129void TextTrackRepresentationCocoa::update()
130130{
131131 if (auto representation = m_client.createTextTrackRepresentationImage())
132  [m_layer.get() setContents:(id)representation->getCGImageRef()];
 132 [m_layer.get() setContents:(id)representation->nativeImage().get()];
133133}
134134
135135void TextTrackRepresentationCocoa::setContentScale(float scale)

Source/WebCore/platform/graphics/mac/ImageMac.mm

@@CFDataRef BitmapImage::getTIFFRepresentation()
8585 if (m_tiffRep)
8686 return m_tiffRep.get();
8787
88  unsigned numFrames = frameCount();
 88 auto nativeImages = this->framesNativeImages();
8989
90  // If numFrames is zero, we know for certain this image doesn't have valid data
 90 // If framesImages.size() is zero, we know for certain this image doesn't have valid data
9191 // Even though the call to CGImageDestinationCreateWithData will fail and we'll handle it gracefully,
9292 // in certain circumstances that call will spam the console with an error message
93  if (!numFrames)
94  return 0;
95 
96  Vector<CGImageRef> images;
97  for (unsigned i = 0; i < numFrames; ++i ) {
98  CGImageRef cgImage = frameImageAtIndex(i).get();
99  if (cgImage)
100  images.append(cgImage);
101  }
102 
103  unsigned numValidFrames = images.size();
 93 if (!nativeImages.size())
 94 return nullptr;
10495
10596 RetainPtr<CFMutableDataRef> data = adoptCF(CFDataCreateMutable(0, 0));
106  RetainPtr<CGImageDestinationRef> destination = adoptCF(CGImageDestinationCreateWithData(data.get(), kUTTypeTIFF, numValidFrames, 0));
 97 RetainPtr<CGImageDestinationRef> destination = adoptCF(CGImageDestinationCreateWithData(data.get(), kUTTypeTIFF, nativeImages.size(), 0));
10798
10899 if (!destination)
109  return 0;
 100 return nullptr;
110101
111  for (unsigned i = 0; i < numValidFrames; ++i)
112  CGImageDestinationAddImage(destination.get(), images[i], 0);
 102 for (auto nativeImage : nativeImages)
 103 CGImageDestinationAddImage(destination.get(), nativeImage.get(), 0);
113104
114105 CGImageDestinationFinalize(destination.get());
115106

Source/WebCore/platform/image-decoders/ImageDecoder.cpp

@@ImageFrame& ImageFrame::operator=(const ImageFrame& other)
142142 return *this;
143143
144144 copyBitmapData(other);
145  setOriginalFrameRect(other.originalFrameRect());
 145 setHasAlpha(other.m_hasAlpha);
146146 setStatus(other.status());
147147 setDuration(other.duration());
148148 setDisposalMethod(other.disposalMethod());

@@ImageFrame& ImageFrame::operator=(const ImageFrame& other)
152152
153153void ImageFrame::clearPixelData()
154154{
155  m_backingStore.clear();
156  m_bytes = 0;
 155 m_pixels = nullptr;
157156 m_status = FrameEmpty;
158157 // NOTE: Do not reset other members here; clearFrameBufferCache() calls this
159158 // to free the bitmap data, but other functions like initFrameBuffer() and

@@void ImageFrame::clearPixelData()
163162
164163void ImageFrame::zeroFillPixelData()
165164{
166  memset(m_bytes, 0, m_size.width() * m_size.height() * sizeof(PixelData));
 165 m_pixels->clear();
167166 m_hasAlpha = true;
168167}
169168
170169void ImageFrame::zeroFillFrameRect(const IntRect& rect)
171170{
172  ASSERT(IntRect(IntPoint(), m_size).contains(rect));
173 
174171 if (rect.isEmpty())
175172 return;
176173
177  size_t rectWidthInBytes = rect.width() * sizeof(PixelData);
178  PixelData* start = m_bytes + (rect.y() * width()) + rect.x();
179  for (int i = 0; i < rect.height(); ++i) {
180  memset(start, 0, rectWidthInBytes);
181  start += width();
182  }
183 
 174 m_pixels->clearRect(rect);
184175 setHasAlpha(true);
185176}
186177

@@bool ImageFrame::copyBitmapData(const ImageFrame& other)
189180 if (this == &other)
190181 return true;
191182
192  m_backingStore = other.m_backingStore;
193  m_bytes = m_backingStore.data();
194  m_size = other.m_size;
195  setHasAlpha(other.m_hasAlpha);
 183 if (other.m_pixels)
 184 m_pixels = BitmapPixels::create(*other.m_pixels.get());
 185 else
 186 m_pixels = nullptr;
196187 return true;
197188}
198189
199190bool ImageFrame::setSize(int newWidth, int newHeight)
200191{
201  ASSERT(!width() && !height());
202  size_t backingStoreSize = newWidth * newHeight;
203  if (!m_backingStore.tryReserveCapacity(backingStoreSize))
204  return false;
205  m_backingStore.resize(backingStoreSize);
206  m_bytes = m_backingStore.data();
207  m_size = IntSize(newWidth, newHeight);
 192 ASSERT(!m_pixels);
 193 m_pixels = BitmapPixels::create(IntSize(newWidth, newHeight), m_premultiplyAlpha);
 194 return m_pixels != nullptr;
 195}
208196
209  zeroFillPixelData();
210  return true;
 197void ImageFrame::copyRowNTimes(int startX, int endX, int startY, int endY)
 198{
 199 m_pixels->repeatFirstRow(IntRect(startX, startY, endX -startX , endY - startY));
211200}
212201
213202bool ImageFrame::hasAlpha() const

@@unsigned ImageDecoder::frameBytesAtIndex(size_t index) const
291280 if (m_frameBufferCache.size() <= index)
292281 return 0;
293282 // FIXME: Use the dimension of the requested frame.
294  return m_size.area() * sizeof(ImageFrame::PixelData);
 283 return m_size.area() * sizeof(RGBA32);
295284}
296285
297286float ImageDecoder::frameDurationAtIndex(size_t index)

Source/WebCore/platform/image-decoders/ImageDecoder.h

2828
2929#pragma once
3030
 31#include "BitmapPixels.h"
3132#include "IntRect.h"
3233#include "ImageSource.h"
3334#include "PlatformScreen.h"

@@using ColorProfile = Vector<char>;
5758 DisposeOverwritePrevious // Clear frame to previous framebuffer
5859 // contents
5960 };
60  typedef unsigned PixelData;
6161
6262 ImageFrame();
6363

@@using ColorProfile = Vector<char>;
8080 // Copies the pixel data at [(startX, startY), (endX, startY)) to the
8181 // same X-coordinates on each subsequent row up to but not including
8282 // endY.
83  void copyRowNTimes(int startX, int endX, int startY, int endY)
84  {
85  ASSERT(startX < width());
86  ASSERT(endX <= width());
87  ASSERT(startY < height());
88  ASSERT(endY <= height());
89  const int rowBytes = (endX - startX) * sizeof(PixelData);
90  const PixelData* const startAddr = getAddr(startX, startY);
91  for (int destY = startY + 1; destY < endY; ++destY)
92  memcpy(getAddr(startX, destY), startAddr, rowBytes);
93  }
 83 void copyRowNTimes(int startX, int endX, int startY, int endY);
9484
9585 // Allocates space for the pixel data. Must be called before any pixels
9686 // are written. Must only be called once. Returns whether allocation
9787 // succeeded.
9888 bool setSize(int newWidth, int newHeight);
 89
 90 IntSize size() const { return m_pixels.size(); }
9991
10092 // Returns a caller-owned pointer to the underlying native image data.
10193 // (Actual use: This pointer will be owned by BitmapImage and freed in
10294 // FrameData::clear()).
103  NativeImagePtr asNewNativeImage() const;
 95 NativeImagePtr asNewNativeImage() const { return m_pixels->image(); }
 96
 97 inline BitmapPixels* pixels() const { return m_pixels ? m_pixels.get() : nullptr; }
 98 inline bool hasPixels() const { return pixels(); }
10499
105100 bool hasAlpha() const;
106  const IntRect& originalFrameRect() const { return m_originalFrameRect; }
107101 FrameStatus status() const { return m_status; }
108102 unsigned duration() const { return m_duration; }
109103 FrameDisposalMethod disposalMethod() const { return m_disposalMethod; }

@@using ColorProfile = Vector<char>;
111105
112106 void setHasAlpha(bool alpha);
113107 void setColorProfile(const ColorProfile&);
114  void setOriginalFrameRect(const IntRect& r) { m_originalFrameRect = r; }
115108 void setStatus(FrameStatus status);
116109 void setDuration(unsigned duration) { m_duration = duration; }
117110 void setDisposalMethod(FrameDisposalMethod method) { m_disposalMethod = method; }

@@using ColorProfile = Vector<char>;
119112
120113 inline void setRGBA(int x, int y, unsigned r, unsigned g, unsigned b, unsigned a)
121114 {
122  setRGBA(getAddr(x, y), r, g, b, a);
 115 m_pixels->setRGBA(x, y, r, g, b, a);
123116 }
124117
125  inline PixelData* getAddr(int x, int y)
 118 inline RGBA32* getAddr(int x, int y)
126119 {
127  return m_bytes + (y * width()) + x;
 120 return m_pixels->at(x, y);
128121 }
129122
130  inline bool hasPixelData() const
 123 inline void setRGBA(RGBA32* dest, unsigned r, unsigned g, unsigned b, unsigned a)
131124 {
132  return m_bytes;
133  }
134 
135  // Use fix point multiplier instead of integer division or floating point math.
136  // This multipler produces exactly the same result for all values in range 0 - 255.
137  static const unsigned fixPointShift = 24;
138  static const unsigned fixPointMult = static_cast<unsigned>(1.0 / 255.0 * (1 << fixPointShift)) + 1;
139  // Multiplies unsigned value by fixpoint value and converts back to unsigned.
140  static unsigned fixPointUnsignedMultiply(unsigned fixed, unsigned v)
141  {
142  return (fixed * v) >> fixPointShift;
143  }
144 
145  inline void setRGBA(PixelData* dest, unsigned r, unsigned g, unsigned b, unsigned a)
146  {
147  if (m_premultiplyAlpha && a < 255) {
148  if (!a) {
149  *dest = 0;
150  return;
151  }
152 
153  unsigned alphaMult = a * fixPointMult;
154  r = fixPointUnsignedMultiply(r, alphaMult);
155  g = fixPointUnsignedMultiply(g, alphaMult);
156  b = fixPointUnsignedMultiply(b, alphaMult);
157  }
158  *dest = (a << 24 | r << 16 | g << 8 | b);
 125 m_pixels->setRGBA(dest, r, g, b, a);
159126 }
160127
161128#if ENABLE(APNG)
162  static inline unsigned divide255(unsigned a)
 129 inline void overRGBA(RGBA32* dest, unsigned r, unsigned g, unsigned b, unsigned a)
163130 {
164  return (a + (a >> 8) + 1) >> 8;
165  }
166 
167  inline void overRGBA(PixelData* dest, unsigned r, unsigned g, unsigned b, unsigned a)
168  {
169  if (!a)
170  return;
171 
172  if (a < 255) {
173  unsigned aDest = ((*dest) >> 24) & 255;
174  if (aDest) {
175  unsigned rDest = ((*dest) >> 16) & 255;
176  unsigned gDest = ((*dest) >> 8) & 255;
177  unsigned bDest = (*dest) & 255;
178  unsigned aAux = 255 - a;
179  if (!m_premultiplyAlpha) {
180  rDest = divide255(rDest * aDest);
181  gDest = divide255(gDest * aDest);
182  bDest = divide255(bDest * aDest);
183  }
184  r = divide255(r * a + rDest * aAux);
185  g = divide255(g * a + gDest * aAux);
186  b = divide255(b * a + bDest * aAux);
187  a += divide255(aDest * aAux);
188  if (!m_premultiplyAlpha) {
189  r = (r * 255 + a - 1) / a;
190  g = (g * 255 + a - 1) / a;
191  b = (b * 255 + a - 1) / a;
192  }
193  } else if (m_premultiplyAlpha) {
194  r = divide255(r * a);
195  g = divide255(g * a);
196  b = divide255(b * a);
197  }
198  }
199  *dest = (a << 24 | r << 16 | g << 8 | b);
 131 m_pixels->overRGBA(dest, r, g, b, a);
200132 }
201133#endif
202134
203135 private:
204  int width() const
205  {
206  return m_size.width();
207  }
 136 std::unique_ptr<BitmapPixels> m_pixels;
208137
209  int height() const
210  {
211  return m_size.height();
212  }
213 
214  Vector<PixelData> m_backingStore;
215  PixelData* m_bytes; // The memory is backed by m_backingStore.
216  IntSize m_size;
217138 // FIXME: Do we need m_colorProfile anymore?
218139 ColorProfile m_colorProfile;
219140 bool m_hasAlpha;
220  IntRect m_originalFrameRect; // This will always just be the entire
221  // buffer except for GIF frames whose
222  // original rect was smaller than the
223  // overall image size.
224141 FrameStatus m_status;
225142 unsigned m_duration;
226143 FrameDisposalMethod m_disposalMethod;

Source/WebCore/platform/image-decoders/bmp/BMPImageReader.cpp

@@bool BMPImageReader::decodeBMP(bool onlySize)
8686 // these 0s could actually show through.
8787 m_buffer->setHasAlpha(false);
8888
89  // For BMPs, the frame always fills the entire image.
90  m_buffer->setOriginalFrameRect(IntRect(IntPoint(), m_parent->size()));
91 
9289 if (!m_isTopDown)
9390 m_coord.setY(m_parent->size().height() - 1);
9491 }

Source/WebCore/platform/image-decoders/cairo/BitmapPixelsCairo.cpp

 1/*
 2 * Copyright (C) 2016 Apple Inc. All rights reserved.
 3 *
 4 * Redistribution and use in source and binary forms, with or without
 5 * modification, are permitted provided that the following conditions
 6 * are met:
 7 * 1. Redistributions of source code must retain the above copyright
 8 * notice, this list of conditions and the following disclaimer.
 9 * 2. Redistributions in binary form must reproduce the above copyright
 10 * notice, this list of conditions and the following disclaimer in the
 11 * documentation and/or other materials provided with the distribution.
 12 *
 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 24 */
 25
 26#include "config.h"
 27#include "BitmapPixels.h"
 28
 29#include <cairo.h>
 30
 31namespace WebCore {
 32
 33NativeImagePtr BitmapPixels::image() const
 34{
 35 return adoptRef(cairo_image_surface_create_for_data(
 36 reinterpret_cast<unsigned char*>(const_cast<RGBA32*>(m_pixels)),
 37 CAIRO_FORMAT_ARGB32, size().width(), size().height(), size().width() * sizeof(RGBA32)));
 38}
 39
 40} // namespace WebCore

Source/WebCore/platform/image-decoders/cairo/ImageDecoderCairo.cpp

1 /*
2  * Copyright (C) 2006 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */
25 
26 #include "config.h"
27 #include "ImageDecoder.h"
28 
29 #include <cairo.h>
30 
31 namespace WebCore {
32 
33 NativeImagePtr ImageFrame::asNewNativeImage() const
34 {
35  return adoptRef(cairo_image_surface_create_for_data(
36  reinterpret_cast<unsigned char*>(const_cast<PixelData*>(m_bytes)),
37  CAIRO_FORMAT_ARGB32, width(), height(), width() * sizeof(PixelData)));
38 }
39 
40 } // namespace WebCore

Source/WebCore/platform/image-decoders/gif/GIFImageDecoder.cpp

@@bool GIFImageDecoder::haveDecodedRow(unsigned frameIndex, const Vector<unsigned
213213
214214 // Initialize the frame if necessary.
215215 ImageFrame& buffer = m_frameBufferCache[frameIndex];
216  if (((buffer.status() == ImageFrame::FrameEmpty) && !initFrameBuffer(frameIndex)) || !buffer.hasPixelData())
 216 if (((buffer.status() == ImageFrame::FrameEmpty) && !initFrameBuffer(frameIndex)) || !buffer.hasPixels())
217217 return false;
218218
219  ImageFrame::PixelData* currentAddress = buffer.getAddr(xBegin, yBegin);
 219 RGBA32* currentAddress = buffer.getAddr(xBegin, yBegin);
220220 // Write one row's worth of data into the frame.
221221 for (int x = xBegin; x < xEnd; ++x) {
222222 const unsigned char sourceValue = rowBuffer[(m_scaled ? m_scaledColumns[x] : x) - frameContext->xOffset];

@@bool GIFImageDecoder::haveDecodedRow(unsigned frameIndex, const Vector<unsigned
240240
241241 // Tell the frame to copy the row data if need be.
242242 if (repeatCount > 1)
243  buffer.copyRowNTimes(xBegin, xEnd, yBegin, yEnd);
 243 buffer.pixels()->copyRowNTimes(xBegin, xEnd, yBegin, yEnd);
244244
245245 return true;
246246}

@@bool GIFImageDecoder::frameComplete(unsigned frameIndex, unsigned frameDuration,
260260 if (!m_currentBufferSawAlpha) {
261261 // The whole frame was non-transparent, so it's possible that the entire
262262 // resulting buffer was non-transparent, and we can setHasAlpha(false).
263  if (buffer.originalFrameRect().contains(IntRect(IntPoint(), scaledSize())))
 263 if (buffer.pixels()->rect().contains(IntRect(IntPoint(), scaledSize())))
264264 buffer.setHasAlpha(false);
265265 else if (frameIndex) {
266266 // Tricky case. This frame does not have alpha only if everywhere

@@bool GIFImageDecoder::frameComplete(unsigned frameIndex, unsigned frameDuration,
283283 // The only remaining case is a DisposeOverwriteBgcolor frame. If
284284 // it had no alpha, and its rect is contained in the current frame's
285285 // rect, we know the current frame has no alpha.
286  if ((prevBuffer->disposalMethod() == ImageFrame::DisposeOverwriteBgcolor) && !prevBuffer->hasAlpha() && buffer.originalFrameRect().contains(prevBuffer->originalFrameRect()))
 286 if ((prevBuffer->disposalMethod() == ImageFrame::DisposeOverwriteBgcolor) && !prevBuffer->hasAlpha() && buffer.pixels()->rect().contains(prevBuffer->pixels()->rect()))
287287 buffer.setHasAlpha(false);
288288 }
289289 }

@@bool GIFImageDecoder::initFrameBuffer(unsigned frameIndex)
353353 frameRect.setHeight(size().height() - frameContext->yOffset);
354354
355355 ImageFrame* const buffer = &m_frameBufferCache[frameIndex];
356  int left = upperBoundScaledX(frameRect.x());
357  int right = lowerBoundScaledX(frameRect.maxX(), left);
358  int top = upperBoundScaledY(frameRect.y());
359  int bottom = lowerBoundScaledY(frameRect.maxY(), top);
360  buffer->setOriginalFrameRect(IntRect(left, top, right - left, bottom - top));
361356
362357 if (!frameIndex) {
363358 // This is the first frame, so we're not relying on any previous data.

@@bool GIFImageDecoder::initFrameBuffer(unsigned frameIndex)
387382 } else {
388383 // We want to clear the previous frame to transparent, without
389384 // affecting pixels in the image outside of the frame.
390  const IntRect& prevRect = prevBuffer->originalFrameRect();
 385 const IntRect& prevRect = prevBuffer->pixels()->rect();
391386 const IntSize& bufferSize = scaledSize();
392387 if (!frameIndex || prevRect.contains(IntRect(IntPoint(), scaledSize()))) {
393388 // Clearing the first frame, or a frame the size of the whole

@@bool GIFImageDecoder::initFrameBuffer(unsigned frameIndex)
402397 }
403398 }
404399 }
 400
 401 int left = upperBoundScaledX(frameRect.x());
 402 int right = lowerBoundScaledX(frameRect.maxX(), left);
 403 int top = upperBoundScaledY(frameRect.y());
 404 int bottom = lowerBoundScaledY(frameRect.maxY(), top);
 405 buffer->pixels->setRect(IntRect(left, top, right - left, bottom - top));
405406
406407 // Update our status to be partially complete.
407408 buffer->setStatus(ImageFrame::FramePartial);

Source/WebCore/platform/image-decoders/jpeg/JPEGImageDecoder.cpp

@@bool JPEGImageDecoder::setFailed()
588588}
589589
590590template <J_COLOR_SPACE colorSpace>
591 void setPixel(ImageFrame& buffer, ImageFrame::PixelData* currentAddress, JSAMPARRAY samples, int column)
 591void setPixel(ImageFrame& buffer, RGBA32* currentAddress, JSAMPARRAY samples, int column)
592592{
593593 JSAMPLE* jsample = *samples + column * (colorSpace == JCS_RGB ? 3 : 4);
594594

@@bool JPEGImageDecoder::outputScanlines(ImageFrame& buffer)
631631 if (destY < 0)
632632 continue;
633633
634  ImageFrame::PixelData* currentAddress = buffer.getAddr(0, destY);
 634 RGBA32* currentAddress = buffer.getAddr(0, destY);
635635 for (int x = 0; x < width; ++x) {
636636 setPixel<colorSpace>(buffer, currentAddress, samples, isScaled ? m_scaledColumns[x] : x);
637637 ++currentAddress;

@@bool JPEGImageDecoder::outputScanlines()
661661 // loading. The completed image will be marked fully opaque in jpegComplete().
662662 buffer.setHasAlpha(true);
663663 buffer.setColorProfile(m_colorProfile);
664 
665  // For JPEGs, the frame always fills the entire image.
666  buffer.setOriginalFrameRect(IntRect(IntPoint(), size()));
667664 }
668665
669666 jpeg_decompress_struct* info = m_reader->info();

Source/WebCore/platform/image-decoders/png/PNGImageDecoder.cpp

@@void PNGImageDecoder::headerAvailable()
452452 }
453453}
454454
455 static inline void setPixelRGB(ImageFrame::PixelData* dest, png_bytep pixel)
 455static inline void setPixelRGB(RGBA32* dest, png_bytep pixel)
456456{
457457 *dest = 0xFF000000U | pixel[0] << 16 | pixel[1] << 8 | pixel[2];
458458}
459459
460 static inline void setPixelRGBA(ImageFrame::PixelData* dest, png_bytep pixel, unsigned char& nonTrivialAlphaMask)
 460static inline void setPixelRGBA(RGBA32* dest, png_bytep pixel, unsigned char& nonTrivialAlphaMask)
461461{
462462 unsigned char a = pixel[3];
463463 *dest = a << 24 | pixel[0] << 16 | pixel[1] << 8 | pixel[2];
464464 nonTrivialAlphaMask |= (255 - a);
465465}
466466
467 static inline void setPixelPremultipliedRGBA(ImageFrame::PixelData* dest, png_bytep pixel, unsigned char& nonTrivialAlphaMask)
 467static inline void setPixelPremultipliedRGBA(RGBA32* dest, png_bytep pixel, unsigned char& nonTrivialAlphaMask)
468468{
469469 unsigned char a = pixel[3];
470470 unsigned char r = fastDivideBy255(pixel[0] * a);

@@void PNGImageDecoder::rowAvailable(unsigned char* rowBuffer, unsigned rowIndex,
513513 initFrameBuffer(m_currentFrame);
514514 else
515515#endif
516  // For PNGs, the frame always fills the entire image.
517  buffer.setOriginalFrameRect(IntRect(IntPoint(), size()));
518516 }
519517
520518 /* libpng comments (here to explain what follows).

@@void PNGImageDecoder::rowAvailable(unsigned char* rowBuffer, unsigned rowIndex,
573571 }
574572
575573 // Write the decoded row pixels to the frame buffer.
576  ImageFrame::PixelData* address = buffer.getAddr(0, y);
 574 RGBA32* address = buffer.getAddr(0, y);
577575 int width = scaledSize().width();
578576 unsigned char nonTrivialAlphaMask = 0;
579577

@@void PNGImageDecoder::initFrameBuffer(size_t frameIndex)
834832 frameRect.setHeight(size().height() - m_yOffset);
835833
836834 ImageFrame& buffer = m_frameBufferCache[frameIndex];
837  int left = upperBoundScaledX(frameRect.x());
838  int right = lowerBoundScaledX(frameRect.maxX(), left);
839  int top = upperBoundScaledY(frameRect.y());
840  int bottom = lowerBoundScaledY(frameRect.maxY(), top);
841  buffer.setOriginalFrameRect(IntRect(left, top, right - left, bottom - top));
842835
843836 // The starting state for this frame depends on the previous frame's
844837 // disposal method.

@@void PNGImageDecoder::initFrameBuffer(size_t frameIndex)
862855 } else {
863856 // We want to clear the previous frame to transparent, without
864857 // affecting pixels in the image outside of the frame.
865  const IntRect& prevRect = prevBuffer->originalFrameRect();
 858 const IntRect& prevRect = prevBuffer->pixels()->rect();
866859 if (!frameIndex || prevRect.contains(IntRect(IntPoint(), scaledSize()))) {
867860 // Clearing the first frame, or a frame the size of the whole
868861 // image, results in a completely empty image.

@@void PNGImageDecoder::initFrameBuffer(size_t frameIndex)
873866 buffer.zeroFillFrameRect(prevRect);
874867 }
875868 }
 869
 870 int left = upperBoundScaledX(frameRect.x());
 871 int right = lowerBoundScaledX(frameRect.maxX(), left);
 872 int top = upperBoundScaledY(frameRect.y());
 873 int bottom = lowerBoundScaledY(frameRect.maxY(), top);
 874 buffer.pixels->setRect(IntRect(left, top, right - left, bottom - top));
876875}
877876
878877void PNGImageDecoder::frameComplete()

@@void PNGImageDecoder::frameComplete()
886885 png_bytep interlaceBuffer = m_reader->interlaceBuffer();
887886
888887 if (m_currentFrame && interlaceBuffer) {
889  const IntRect& rect = buffer.originalFrameRect();
 888 const IntRect& rect = buffer.pixels()->rect();
890889 bool hasAlpha = m_reader->hasAlpha();
891890 unsigned colorChannels = hasAlpha ? 4 : 3;
892891 bool nonTrivialAlpha = false;

@@void PNGImageDecoder::frameComplete()
896895#if ENABLE(IMAGE_DECODER_DOWN_SAMPLING)
897896 for (int y = 0; y < rect.maxY() - rect.y(); ++y) {
898897 png_bytep row = interlaceBuffer + (m_scaled ? m_scaledRows[y] : y) * colorChannels * size().width();
899  ImageFrame::PixelData* address = buffer.getAddr(rect.x(), y + rect.y());
 898 RGBA32* address = buffer.getAddr(rect.x(), y + rect.y());
900899 for (int x = 0; x < rect.maxX() - rect.x(); ++x) {
901900 png_bytep pixel = row + (m_scaled ? m_scaledColumns[x] : x) * colorChannels;
902901 unsigned alpha = hasAlpha ? pixel[3] : 255;

@@void PNGImageDecoder::frameComplete()
912911 png_bytep row = interlaceBuffer;
913912 for (int y = rect.y(); y < rect.maxY(); ++y, row += colorChannels * size().width()) {
914913 png_bytep pixel = row;
915  ImageFrame::PixelData* address = buffer.getAddr(rect.x(), y);
 914 RGBA32* address = buffer.getAddr(rect.x(), y);
916915 for (int x = rect.x(); x < rect.maxX(); ++x, pixel += colorChannels) {
917916 unsigned alpha = hasAlpha ? pixel[3] : 255;
918917 nonTrivialAlpha |= alpha < 255;

@@void PNGImageDecoder::frameComplete()
925924#endif
926925
927926 if (!nonTrivialAlpha) {
928  if (buffer.originalFrameRect().contains(IntRect(IntPoint(), scaledSize())))
 927 if (buffer.pixels()->rect().contains(IntRect(IntPoint(), scaledSize())))
929928 buffer.setHasAlpha(false);
930929 else {
931930 size_t frameIndex = m_currentFrame;

@@void PNGImageDecoder::frameComplete()
933932 while (frameIndex && (prevBuffer->disposalMethod() == ImageFrame::DisposeOverwritePrevious))
934933 prevBuffer = &m_frameBufferCache[--frameIndex];
935934 if ((prevBuffer->disposalMethod() == ImageFrame::DisposeOverwriteBgcolor)
936  && !prevBuffer->hasAlpha() && buffer.originalFrameRect().contains(prevBuffer->originalFrameRect()))
 935 && !prevBuffer->hasAlpha() && buffer.pixels()->rect().contains(prevBuffer->pixels()->rect()))
937936 buffer.setHasAlpha(false);
938937 }
939938 } else if (!m_blend && !buffer.hasAlpha())

Source/WebCore/platform/image-decoders/webp/WEBPImageDecoder.cpp

@@bool WEBPImageDecoder::decode(bool onlySize)
132132 return setFailed();
133133 buffer.setStatus(ImageFrame::FramePartial);
134134 buffer.setHasAlpha(m_hasAlpha);
135  buffer.setOriginalFrameRect(IntRect(IntPoint(), size()));
136135 }
137136
138137 if (!m_decoder) {
139138 WEBP_CSP_MODE mode = outputMode(m_hasAlpha);
140139 if (!m_premultiplyAlpha)
141140 mode = outputMode(false);
142  int rowStride = size().width() * sizeof(ImageFrame::PixelData);
 141 int rowStride = size().width() * sizeof(RGBA32);
143142 uint8_t* output = reinterpret_cast<uint8_t*>(buffer.getAddr(0, 0));
144143 int outputSize = size().height() * rowStride;
145144 m_decoder = WebPINewRGB(mode, output, outputSize, rowStride);

Source/WebCore/platform/mediastream/mac/MockRealtimeVideoSourceMac.mm

@@void MockRealtimeVideoSourceMac::updatePlatformLayer() const
8787 if (!image)
8888 break;
8989
90  m_previewImage = image->getCGImageRef();
 90 m_previewImage = image->nativeImage();
9191 if (!m_previewImage)
9292 break;
9393

Source/WebCore/platform/win/DragImageCGWin.cpp

@@DragImageRef createDragImageFromImage(Image* img, ImageOrientationDescription)
136136 CGContextScaleCTM(drawContext, 1, -1);
137137 CGContextSetFillColor(drawContext, white);
138138 CGContextFillRect(drawContext, rect);
139  if (auto srcImage = img->getCGImageRef()) {
 139 if (auto srcImage = img->nativeImage()) {
140140 CGContextSetBlendMode(drawContext, kCGBlendModeNormal);
141  CGContextDrawImage(drawContext, rect, srcImage);
 141 CGContextDrawImage(drawContext, rect, srcImage.get());
142142 }
143143 CGContextRelease(drawContext);
144144

Source/WebKit/mac/Misc/WebCache.mm

@@+ (CGImageRef)imageForURL:(NSURL *)url
204204 WebCore::CachedImage& cachedImage = downcast<WebCore::CachedImage>(*cachedResource);
205205 if (!cachedImage.hasImage())
206206 return nullptr;
207  return cachedImage.image()->getCGImageRef();
 207 return cachedImage.image()->nativeImage().get();
208208}
209209
210210#endif // PLATFORM(IOS)

Source/WebKit2/UIProcess/API/C/cg/WKIconDatabaseCG.cpp

@@using namespace WebCore;
3737CGImageRef WKIconDatabaseTryGetCGImageForURL(WKIconDatabaseRef iconDatabaseRef, WKURLRef urlRef, WKSize size)
3838{
3939 Image* image = toImpl(iconDatabaseRef)->imageForPageURL(toWTFString(urlRef));
40  return image ? image->getFirstCGImageRefOfSize(IntSize(static_cast<int>(size.width), static_cast<int>(size.height))) : 0;
 40 return image ? image->nativeImageOfSize(IntSize(static_cast<int>(size.width), static_cast<int>(size.height))).get() : nullptr;
4141}
4242
4343CFArrayRef WKIconDatabaseTryCopyCGImageArrayForURL(WKIconDatabaseRef iconDatabaseRef, WKURLRef urlRef)
4444{
4545 Image* image = toImpl(iconDatabaseRef)->imageForPageURL(toWTFString(urlRef));
46  return image ? image->getCGImageArray().leakRef() : 0;
 46 if (!image)
 47 return nullptr;
 48
 49 auto nativeImages = image->framesNativeImages();
 50 if (!nativeImages.size())
 51 return nullptr;
 52
 53 CFMutableArrayRef array = CFArrayCreateMutable(nullptr, nativeImages.size(), &kCFTypeArrayCallBacks);
 54 for (auto nativeImage : nativeImages)
 55 CFArrayAppendValue(array, nativeImage.get());
 56
 57 return static_cast<CFArrayRef>(CFRetain(array));
4758}
4859

Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm

@@- (UIImage *)_presentationSnapshotForPreviewItemController:(UIPreviewItemControl
40714071{
40724072 if (!_positionInformation.linkIndicator.contentImage)
40734073 return nullptr;
4074  return [[[UIImage alloc] initWithCGImage:_positionInformation.linkIndicator.contentImage->getCGImageRef()] autorelease];
 4074 return [[[UIImage alloc] initWithCGImage:_positionInformation.linkIndicator.contentImage->nativeImage().get()] autorelease];
40754075}
40764076
40774077- (NSArray *)_presentationRectsForPreviewItemController:(UIPreviewItemController *)controller

Source/WebKit2/WebProcess/Plugins/PluginView.cpp

@@void PluginView::windowedPluginVisibilityDidChange(bool isVisible, uint64_t wind
17271727}
17281728#endif
17291729
1730 #if PLATFORM(COCOA)
1731 static bool isAlmostSolidColor(BitmapImage* bitmap)
1732 {
1733  CGImageRef image = bitmap->getCGImageRef();
1734  ASSERT(CGImageGetBitsPerComponent(image) == 8);
1735 
1736  CGBitmapInfo imageInfo = CGImageGetBitmapInfo(image);
1737  if (!(imageInfo & kCGBitmapByteOrder32Little) || (imageInfo & kCGBitmapAlphaInfoMask) != kCGImageAlphaPremultipliedFirst) {
1738  // FIXME: Consider being able to handle other pixel formats.
1739  ASSERT_NOT_REACHED();
1740  return false;
1741  }
1742 
1743  size_t width = CGImageGetWidth(image);
1744  size_t height = CGImageGetHeight(image);
1745  size_t bytesPerRow = CGImageGetBytesPerRow(image);
1746 
1747  RetainPtr<CFDataRef> provider = adoptCF(CGDataProviderCopyData(CGImageGetDataProvider(image)));
1748  const UInt8* data = CFDataGetBytePtr(provider.get());
1749 
1750  // Overlay a grid of sampling dots on top of a grayscale version of the image.
1751  // For the interior points, calculate the difference in luminance among the sample point
1752  // and its surrounds points, scaled by transparency.
1753  const unsigned sampleRows = 7;
1754  const unsigned sampleCols = 7;
1755  // FIXME: Refine the proper number of samples, and accommodate different aspect ratios.
1756  if (width < sampleCols || height < sampleRows)
1757  return false;
1758 
1759  // Ensure that the last row/column land on the image perimeter.
1760  const float strideWidth = static_cast<float>(width - 1) / (sampleCols - 1);
1761  const float strideHeight = static_cast<float>(height - 1) / (sampleRows - 1);
1762  float samples[sampleRows][sampleCols];
1763 
1764  // Find the luminance of the sample points.
1765  float y = 0;
1766  const UInt8* row = data;
1767  for (unsigned i = 0; i < sampleRows; ++i) {
1768  float x = 0;
1769  for (unsigned j = 0; j < sampleCols; ++j) {
1770  const UInt8* p0 = row + (static_cast<int>(x + .5)) * 4;
1771  // R G B A
1772  samples[i][j] = (0.2125 * *p0 + 0.7154 * *(p0+1) + 0.0721 * *(p0+2)) * *(p0+3) / 255;
1773  x += strideWidth;
1774  }
1775  y += strideHeight;
1776  row = data + (static_cast<int>(y + .5)) * bytesPerRow;
1777  }
1778 
1779  // Determine the image score.
1780  float accumScore = 0;
1781  for (unsigned i = 1; i < sampleRows - 1; ++i) {
1782  for (unsigned j = 1; j < sampleCols - 1; ++j) {
1783  float diff = samples[i - 1][j] + samples[i + 1][j] + samples[i][j - 1] + samples[i][j + 1] - 4 * samples[i][j];
1784  accumScore += diff * diff;
1785  }
1786  }
1787 
1788  // The score for a given sample can be within the range of 0 and 255^2.
1789  return accumScore < 2500 * (sampleRows - 2) * (sampleCols - 2);
1790 }
1791 #endif
1792 
17931730void PluginView::pluginSnapshotTimerFired()
17941731{
17951732#if ENABLE(PRIMARY_SNAPSHOTTED_PLUGIN_HEURISTIC)

@@void PluginView::pluginSnapshotTimerFired()
18091746
18101747 if (snapshotImage) {
18111748#if ENABLE(PRIMARY_SNAPSHOTTED_PLUGIN_HEURISTIC)
1812  bool snapshotIsAlmostSolidColor = isAlmostSolidColor(downcast<BitmapImage>(snapshotImage.get()));
 1749 bool snapshotIsAlmostSolidColor = static_pointer_cast<BitmapImage>(snapshotImage)->isAlmostSolidColor();
18131750 snapshotFound = !snapshotIsAlmostSolidColor;
18141751#endif
18151752