Source/WebCore/ChangeLog

112016-01-06 Simon Fraser <simon.fraser@apple.com>
22
 3 Initial implementation files for display-list recording and playback
 4 https://bugs.webkit.org/show_bug.cgi?id=152816
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 Add files for:
 9 - DisplayList, a class that holds a vector of display items, and in future will hold metadata
 10 on the list for optimizations etc.
 11 - DisplayList::Recorder, the outward-facing recording API which GraphicsContext will
 12 call into.
 13 - DisplayList::Replayer, which plays back a DisplayList, possibly applying optimizations.
 14 - Various DisplayList::Items, one type for each display list operation. They cover most of the
 15 GraphicsContext functionality, other than clipping to an image buffer. Text drawing is stubbed
 16 out for now.
 17
 18 Added a "DisplayLists" log channel.
 19
 20 Added GraphicsContextState functions for tracking state deltas with change bits. It may
 21 make sense to combine GraphicsContextStateChange and GraphicsContextState, and use the
 22 dirty bits in non-display-list drawing as well.
 23
 24 * CMakeLists.txt:
 25 * WebCore.xcodeproj/project.pbxproj:
 26 * platform/Logging.h:
 27 * platform/graphics/GraphicsContext.h:
 28 * platform/graphics/displaylists/DisplayList.cpp: Added.
 29 (WebCore::DisplayList::DisplayList::description):
 30 (WebCore::DisplayList::DisplayList::dump):
 31 (WebCore::operator<<):
 32 * platform/graphics/displaylists/DisplayListItems.cpp: Added.
 33 * platform/graphics/displaylists/DisplayListItems.h: Added.
 34 * platform/graphics/displaylists/DisplayListRecorder.cpp: Added.
 35 * platform/graphics/displaylists/DisplayListRecorder.h: Added.
 36 * platform/graphics/displaylists/DisplayListReplayer.cpp: Added.
 37 (WebCore::DisplayList::Replayer::Replayer):
 38 (WebCore::DisplayList::Replayer::~Replayer):
 39 (WebCore::DisplayList::Replayer::replay):
 40 * platform/graphics/displaylists/DisplayListReplayer.h: Added.
 41
 422016-01-06 Simon Fraser <simon.fraser@apple.com>
 43
344 Sort the project file.
445
546 * WebCore.xcodeproj/project.pbxproj:

Source/WebCore/CMakeLists.txt

@@set(WebCore_INCLUDE_DIRECTORIES
7070 "${WEBCORE_DIR}/platform/graphics"
7171 "${WEBCORE_DIR}/platform/graphics/cpu/arm"
7272 "${WEBCORE_DIR}/platform/graphics/cpu/arm/filters"
 73 "${WEBCORE_DIR}/platform/graphics/displaylists"
7374 "${WEBCORE_DIR}/platform/graphics/filters"
7475 "${WEBCORE_DIR}/platform/graphics/filters/texmap"
7576 "${WEBCORE_DIR}/platform/graphics/harfbuzz"

@@set(WebCore_SOURCES
22152216
22162217 platform/graphics/cpu/arm/filters/FELightingNEON.cpp
22172218
 2219 platform/graphics/displaylists/DisplayList.cpp
 2220 platform/graphics/displaylists/DisplayListItems.cpp
 2221 platform/graphics/displaylists/DisplayListRecorder.cpp
 2222 platform/graphics/displaylists/DisplayListReplayer.cpp
 2223
22182224 platform/graphics/filters/DistantLightSource.cpp
22192225 platform/graphics/filters/FEBlend.cpp
22202226 platform/graphics/filters/FEColorMatrix.cpp

Source/WebCore/WebCore.xcodeproj/project.pbxproj

550550 0FDF45A91BD1C82500E4FA8C /* TimingFunction.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0FDF45A81BD1C82500E4FA8C /* TimingFunction.cpp */; };
551551 0FE5806319327A6200DE32EB /* ScrollingTreeMac.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0FE5806119327A6200DE32EB /* ScrollingTreeMac.cpp */; };
552552 0FE5806419327A6200DE32EB /* ScrollingTreeMac.h in Headers */ = {isa = PBXBuildFile; fileRef = 0FE5806219327A6200DE32EB /* ScrollingTreeMac.h */; };
 553 0FE5FBD21C3DD51E0007A2CA /* DisplayList.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0FE5FBCA1C3DD51E0007A2CA /* DisplayList.cpp */; };
 554 0FE5FBD31C3DD51E0007A2CA /* DisplayList.h in Headers */ = {isa = PBXBuildFile; fileRef = 0FE5FBCB1C3DD51E0007A2CA /* DisplayList.h */; };
 555 0FE5FBD41C3DD51E0007A2CA /* DisplayListItems.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0FE5FBCC1C3DD51E0007A2CA /* DisplayListItems.cpp */; };
 556 0FE5FBD51C3DD51E0007A2CA /* DisplayListItems.h in Headers */ = {isa = PBXBuildFile; fileRef = 0FE5FBCD1C3DD51E0007A2CA /* DisplayListItems.h */; };
 557 0FE5FBD61C3DD51E0007A2CA /* DisplayListRecorder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0FE5FBCE1C3DD51E0007A2CA /* DisplayListRecorder.cpp */; };
 558 0FE5FBD71C3DD51E0007A2CA /* DisplayListRecorder.h in Headers */ = {isa = PBXBuildFile; fileRef = 0FE5FBCF1C3DD51E0007A2CA /* DisplayListRecorder.h */; };
 559 0FE5FBD81C3DD51E0007A2CA /* DisplayListReplayer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0FE5FBD01C3DD51E0007A2CA /* DisplayListReplayer.cpp */; };
 560 0FE5FBD91C3DD51E0007A2CA /* DisplayListReplayer.h in Headers */ = {isa = PBXBuildFile; fileRef = 0FE5FBD11C3DD51E0007A2CA /* DisplayListReplayer.h */; };
553561 0FE71405142170B800DB33BA /* ScrollbarThemeMock.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0FE71403142170B800DB33BA /* ScrollbarThemeMock.cpp */; };
554562 0FE71406142170B800DB33BA /* ScrollbarThemeMock.h in Headers */ = {isa = PBXBuildFile; fileRef = 0FE71404142170B800DB33BA /* ScrollbarThemeMock.h */; };
555563 0FEA3E7B191B2FC5000F1B55 /* ScrollingStateFrameScrollingNode.h in Headers */ = {isa = PBXBuildFile; fileRef = 0FEA3E79191B2FC5000F1B55 /* ScrollingStateFrameScrollingNode.h */; settings = {ATTRIBUTES = (Private, ); }; };

78397847 0FDF45A81BD1C82500E4FA8C /* TimingFunction.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TimingFunction.cpp; sourceTree = "<group>"; };
78407848 0FE5806119327A6200DE32EB /* ScrollingTreeMac.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ScrollingTreeMac.cpp; sourceTree = "<group>"; };
78417849 0FE5806219327A6200DE32EB /* ScrollingTreeMac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScrollingTreeMac.h; sourceTree = "<group>"; };
 7850 0FE5FBCA1C3DD51E0007A2CA /* DisplayList.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = DisplayList.cpp; path = displaylists/DisplayList.cpp; sourceTree = "<group>"; };
 7851 0FE5FBCB1C3DD51E0007A2CA /* DisplayList.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DisplayList.h; path = displaylists/DisplayList.h; sourceTree = "<group>"; };
 7852 0FE5FBCC1C3DD51E0007A2CA /* DisplayListItems.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = DisplayListItems.cpp; path = displaylists/DisplayListItems.cpp; sourceTree = "<group>"; };
 7853 0FE5FBCD1C3DD51E0007A2CA /* DisplayListItems.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DisplayListItems.h; path = displaylists/DisplayListItems.h; sourceTree = "<group>"; };
 7854 0FE5FBCE1C3DD51E0007A2CA /* DisplayListRecorder.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = DisplayListRecorder.cpp; path = displaylists/DisplayListRecorder.cpp; sourceTree = "<group>"; };
 7855 0FE5FBCF1C3DD51E0007A2CA /* DisplayListRecorder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DisplayListRecorder.h; path = displaylists/DisplayListRecorder.h; sourceTree = "<group>"; };
 7856 0FE5FBD01C3DD51E0007A2CA /* DisplayListReplayer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = DisplayListReplayer.cpp; path = displaylists/DisplayListReplayer.cpp; sourceTree = "<group>"; };
 7857 0FE5FBD11C3DD51E0007A2CA /* DisplayListReplayer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DisplayListReplayer.h; path = displaylists/DisplayListReplayer.h; sourceTree = "<group>"; };
78427858 0FE71403142170B800DB33BA /* ScrollbarThemeMock.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ScrollbarThemeMock.cpp; sourceTree = "<group>"; };
78437859 0FE71404142170B800DB33BA /* ScrollbarThemeMock.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScrollbarThemeMock.h; sourceTree = "<group>"; };
78447860 0FE71415142189FC00DB33BA /* ScrollbarTheme.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ScrollbarTheme.cpp; sourceTree = "<group>"; };

1565415670 path = ios;
1565515671 sourceTree = "<group>";
1565615672 };
 15673 0FE5FBC91C3DD5060007A2CA /* displaylists */ = {
 15674 isa = PBXGroup;
 15675 children = (
 15676 0FE5FBCA1C3DD51E0007A2CA /* DisplayList.cpp */,
 15677 0FE5FBCB1C3DD51E0007A2CA /* DisplayList.h */,
 15678 0FE5FBCC1C3DD51E0007A2CA /* DisplayListItems.cpp */,
 15679 0FE5FBCD1C3DD51E0007A2CA /* DisplayListItems.h */,
 15680 0FE5FBCE1C3DD51E0007A2CA /* DisplayListRecorder.cpp */,
 15681 0FE5FBCF1C3DD51E0007A2CA /* DisplayListRecorder.h */,
 15682 0FE5FBD01C3DD51E0007A2CA /* DisplayListReplayer.cpp */,
 15683 0FE5FBD11C3DD51E0007A2CA /* DisplayListReplayer.h */,
 15684 );
 15685 name = displaylists;
 15686 sourceTree = "<group>";
 15687 };
1565715688 14DFB33F0A7DF7630018F769 /* Derived Sources */ = {
1565815689 isa = PBXGroup;
1565915690 children = (

2152921560 B27535290B053814002CE64F /* cg */,
2153021561 B5320D68122A24E9002D1440 /* cocoa */,
2153121562 9332AB3B16515D7700D827EC /* cpu */,
 21563 0FE5FBC91C3DD5060007A2CA /* displaylists */,
2153221564 A75E8B7F0E1DE2B0007F2481 /* filters */,
2153321565 498770C11242C50D002226BA /* gpu */,
2153421566 441AF0A70EBA7BBF0044ED4B /* ios */,

2506825100 2D5646B01B8F8493003C4994 /* DictionaryPopupInfo.h in Headers */,
2506925101 FDAF19991513D131008DB0C3 /* DirectConvolver.h in Headers */,
2507025102 7EDAAFC919A2CCDC0034DFD1 /* DiskCacheMonitorCocoa.h in Headers */,
 25103 0FE5FBD31C3DD51E0007A2CA /* DisplayList.h in Headers */,
 25104 0FE5FBD51C3DD51E0007A2CA /* DisplayListItems.h in Headers */,
 25105 0FE5FBD71C3DD51E0007A2CA /* DisplayListRecorder.h in Headers */,
 25106 0FE5FBD91C3DD51E0007A2CA /* DisplayListReplayer.h in Headers */,
2507125107 49AF2D6914435D050016A784 /* DisplayRefreshMonitor.h in Headers */,
2507225108 2D29ECC6192ECC8300984B78 /* DisplayRefreshMonitorClient.h in Headers */,
2507325109 2D29ECCA192F1F1D00984B78 /* DisplayRefreshMonitorIOS.h in Headers */,

2890228938 937FF3D71A10131B008EBA31 /* DictionaryLookup.mm in Sources */,
2890328939 FDAF19981513D131008DB0C3 /* DirectConvolver.cpp in Sources */,
2890428940 7E4DE10D198B10B60051CB02 /* DiskCacheMonitorCocoa.mm in Sources */,
 28941 0FE5FBD21C3DD51E0007A2CA /* DisplayList.cpp in Sources */,
 28942 0FE5FBD41C3DD51E0007A2CA /* DisplayListItems.cpp in Sources */,
 28943 0FE5FBD61C3DD51E0007A2CA /* DisplayListRecorder.cpp in Sources */,
 28944 0FE5FBD81C3DD51E0007A2CA /* DisplayListReplayer.cpp in Sources */,
2890528945 49FC7A501444AF5F00A5D864 /* DisplayRefreshMonitor.cpp in Sources */,
2890628946 2D29ECC5192ECC8300984B78 /* DisplayRefreshMonitorClient.cpp in Sources */,
2890728947 0F97A658155DA81E00FADD4C /* DisplayRefreshMonitorIOS.mm in Sources */,

Source/WebCore/platform/Logging.h

@@namespace WebCore {
4848 M(Archives) \
4949 M(Compositing) \
5050 M(ContentFiltering) \
 51 M(DisplayLists) \
5152 M(DOMTimers) \
5253 M(Editing) \
5354 M(Events) \

Source/WebCore/platform/graphics/GraphicsContext.cpp

3434#include "IntRect.h"
3535#include "RoundedRect.h"
3636#include "TextRun.h"
 37#include "TextStream.h"
3738
3839namespace WebCore {
3940

@@private:
9899 bool m_interpolationQualityChanged;
99100};
100101
 102
 103#define CHECK_FOR_CHANGED_PROPERTY(flag, property) \
 104 if ((m_changeFlags & GraphicsContextState::flag) && (m_state.property != state.property)) \
 105 changeFlags |= GraphicsContextState::flag;
 106
 107GraphicsContextState::StateChangeFlags GraphicsContextStateChange::changesFromState(const GraphicsContextState& state) const
 108{
 109 GraphicsContextState::StateChangeFlags changeFlags = 0;
 110
 111 CHECK_FOR_CHANGED_PROPERTY(StrokeGradientChange, strokeGradient);
 112 CHECK_FOR_CHANGED_PROPERTY(StrokePatternChange, strokePattern);
 113 CHECK_FOR_CHANGED_PROPERTY(FillGradientChange, fillGradient);
 114 CHECK_FOR_CHANGED_PROPERTY(FillPatternChange, fillPattern);
 115
 116 if ((m_changeFlags & GraphicsContextState::ShadowChange)
 117 && (m_state.shadowOffset != state.shadowOffset
 118 || m_state.shadowBlur != state.shadowBlur
 119 || m_state.shadowColor != state.shadowColor))
 120 changeFlags |= GraphicsContextState::ShadowChange;
 121
 122 CHECK_FOR_CHANGED_PROPERTY(StrokeThicknessChange, strokeThickness);
 123 CHECK_FOR_CHANGED_PROPERTY(TextDrawingModeChange, textDrawingMode);
 124 CHECK_FOR_CHANGED_PROPERTY(StrokeColorChange, strokeColor);
 125 CHECK_FOR_CHANGED_PROPERTY(FillColorChange, fillColor);
 126 CHECK_FOR_CHANGED_PROPERTY(StrokeStyleChange, strokeStyle);
 127 CHECK_FOR_CHANGED_PROPERTY(FillRuleChange, fillRule);
 128 CHECK_FOR_CHANGED_PROPERTY(AlphaChange, alpha);
 129
 130 if ((m_changeFlags & (GraphicsContextState::CompositeOperationChange | GraphicsContextState::BlendModeChange))
 131 && (m_state.compositeOperator != state.compositeOperator || m_state.blendMode != state.blendMode))
 132 changeFlags |= (GraphicsContextState::CompositeOperationChange | GraphicsContextState::BlendModeChange);
 133
 134 CHECK_FOR_CHANGED_PROPERTY(ShouldAntialiasChange, shouldAntialias);
 135 CHECK_FOR_CHANGED_PROPERTY(ShouldSmoothFontsChange, shouldSmoothFonts);
 136 CHECK_FOR_CHANGED_PROPERTY(AntialiasedFontDilationEnabledChange, antialiasedFontDilationEnabled);
 137 CHECK_FOR_CHANGED_PROPERTY(ShouldSubpixelQuantizeFontsChange, shouldSubpixelQuantizeFonts);
 138 CHECK_FOR_CHANGED_PROPERTY(ShadowsIgnoreTransformsChange, shadowsIgnoreTransforms);
 139 CHECK_FOR_CHANGED_PROPERTY(DrawLuminanceMaskChange, drawLuminanceMask);
 140 CHECK_FOR_CHANGED_PROPERTY(ImageInterpolationQualityChange, imageInterpolationQuality);
 141
 142 return changeFlags;
 143}
 144
 145void GraphicsContextStateChange::accumulate(const GraphicsContextState& state, GraphicsContextState::StateChangeFlags flags)
 146{
 147 // FIXME: this code should move to GraphicsContextState.
 148 if (flags & GraphicsContextState::StrokeGradientChange)
 149 m_state.strokeGradient = state.strokeGradient;
 150
 151 if (flags & GraphicsContextState::StrokePatternChange)
 152 m_state.strokePattern = state.strokePattern;
 153
 154 if (flags & GraphicsContextState::FillGradientChange)
 155 m_state.fillGradient = state.fillGradient;
 156
 157 if (flags & GraphicsContextState::FillPatternChange)
 158 m_state.fillPattern = state.fillPattern;
 159
 160 if (flags & GraphicsContextState::ShadowChange) {
 161 // FIXME: deal with state.shadowsUseLegacyRadius)
 162 m_state.shadowOffset = state.shadowOffset;
 163 m_state.shadowBlur = state.shadowBlur;
 164 m_state.shadowColor = state.shadowColor;
 165 }
 166
 167 if (flags & GraphicsContextState::StrokeThicknessChange)
 168 m_state.strokeThickness = state.strokeThickness;
 169
 170 if (flags & GraphicsContextState::TextDrawingModeChange)
 171 m_state.textDrawingMode = state.textDrawingMode;
 172
 173 if (flags & GraphicsContextState::StrokeColorChange)
 174 m_state.strokeColor = state.strokeColor;
 175
 176 if (flags & GraphicsContextState::FillColorChange)
 177 m_state.fillColor = state.fillColor;
 178
 179 if (flags & GraphicsContextState::StrokeStyleChange)
 180 m_state.strokeStyle = state.strokeStyle;
 181
 182 if (flags & GraphicsContextState::FillRuleChange)
 183 m_state.fillRule = state.fillRule;
 184
 185 if (flags & GraphicsContextState::AlphaChange)
 186 m_state.alpha = state.alpha;
 187
 188 if (flags & (GraphicsContextState::CompositeOperationChange | GraphicsContextState::BlendModeChange)) {
 189 m_state.compositeOperator = state.compositeOperator;
 190 m_state.blendMode = state.blendMode;
 191 }
 192
 193 if (flags & GraphicsContextState::ShouldAntialiasChange)
 194 m_state.shouldAntialias = state.shouldAntialias;
 195
 196 if (flags & GraphicsContextState::ShouldSmoothFontsChange)
 197 m_state.shouldSmoothFonts = state.shouldSmoothFonts;
 198
 199 if (flags & GraphicsContextState::AntialiasedFontDilationEnabledChange)
 200 m_state.antialiasedFontDilationEnabled = state.antialiasedFontDilationEnabled;
 201
 202 if (flags & GraphicsContextState::ShouldSubpixelQuantizeFontsChange)
 203 m_state.shouldSubpixelQuantizeFonts = state.shouldSubpixelQuantizeFonts;
 204
 205 if (flags & GraphicsContextState::ShadowsIgnoreTransformsChange)
 206 m_state.shadowsIgnoreTransforms = state.shadowsIgnoreTransforms;
 207
 208 if (flags & GraphicsContextState::DrawLuminanceMaskChange)
 209 m_state.drawLuminanceMask = state.drawLuminanceMask;
 210
 211 if (flags & GraphicsContextState::ImageInterpolationQualityChange)
 212 m_state.imageInterpolationQuality = state.imageInterpolationQuality;
 213
 214 m_changeFlags |= flags;
 215}
 216
 217void GraphicsContextStateChange::apply(GraphicsContext& context) const
 218{
 219 if (m_changeFlags & GraphicsContextState::StrokeGradientChange)
 220 context.setStrokeGradient(*m_state.strokeGradient);
 221
 222 if (m_changeFlags & GraphicsContextState::StrokePatternChange)
 223 context.setStrokePattern(*m_state.strokePattern);
 224
 225 if (m_changeFlags & GraphicsContextState::FillGradientChange)
 226 context.setFillGradient(*m_state.fillGradient);
 227
 228 if (m_changeFlags & GraphicsContextState::FillPatternChange)
 229 context.setFillPattern(*m_state.fillPattern);
 230
 231 if (m_changeFlags & GraphicsContextState::ShadowChange) {
 232#if USE(CG)
 233 if (m_state.shadowsUseLegacyRadius)
 234 context.setLegacyShadow(m_state.shadowOffset, m_state.shadowBlur, m_state.shadowColor);
 235 else
 236#endif
 237 context.setShadow(m_state.shadowOffset, m_state.shadowBlur, m_state.shadowColor);
 238 }
 239
 240 if (m_changeFlags & GraphicsContextState::StrokeThicknessChange)
 241 context.setStrokeThickness(m_state.strokeThickness);
 242
 243 if (m_changeFlags & GraphicsContextState::TextDrawingModeChange)
 244 context.setTextDrawingMode(m_state.textDrawingMode);
 245
 246 if (m_changeFlags & GraphicsContextState::StrokeColorChange)
 247 context.setStrokeColor(m_state.strokeColor);
 248
 249 if (m_changeFlags & GraphicsContextState::FillColorChange)
 250 context.setFillColor(m_state.fillColor);
 251
 252 if (m_changeFlags & GraphicsContextState::StrokeStyleChange)
 253 context.setStrokeStyle(m_state.strokeStyle);
 254
 255 if (m_changeFlags & GraphicsContextState::FillRuleChange)
 256 context.setFillRule(m_state.fillRule);
 257
 258 if (m_changeFlags & GraphicsContextState::AlphaChange)
 259 context.setAlpha(m_state.alpha);
 260
 261 if (m_changeFlags & (GraphicsContextState::CompositeOperationChange | GraphicsContextState::BlendModeChange))
 262 context.setCompositeOperation(m_state.compositeOperator, m_state.blendMode);
 263
 264 if (m_changeFlags & GraphicsContextState::ShouldAntialiasChange)
 265 context.setShouldAntialias(m_state.shouldAntialias);
 266
 267 if (m_changeFlags & GraphicsContextState::ShouldSmoothFontsChange)
 268 context.setShouldSmoothFonts(m_state.shouldSmoothFonts);
 269
 270 if (m_changeFlags & GraphicsContextState::AntialiasedFontDilationEnabledChange)
 271 context.setAntialiasedFontDilationEnabled(m_state.antialiasedFontDilationEnabled);
 272
 273 if (m_changeFlags & GraphicsContextState::ShouldSubpixelQuantizeFontsChange)
 274 context.setShouldSubpixelQuantizeFonts(m_state.shouldSubpixelQuantizeFonts);
 275
 276 if (m_changeFlags & GraphicsContextState::ShadowsIgnoreTransformsChange)
 277 context.setShadowsIgnoreTransforms(m_state.shadowsIgnoreTransforms);
 278
 279 if (m_changeFlags & GraphicsContextState::DrawLuminanceMaskChange)
 280 context.setDrawLuminanceMask(m_state.drawLuminanceMask);
 281
 282 if (m_changeFlags & GraphicsContextState::ImageInterpolationQualityChange)
 283 context.setImageInterpolationQuality(m_state.imageInterpolationQuality);
 284}
 285
 286void GraphicsContextStateChange::dump(TextStream& ts) const
 287{
 288 ts.dumpProperty("change-flags", m_changeFlags);
 289
 290 if (m_changeFlags & GraphicsContextState::StrokeGradientChange)
 291 ts.dumpProperty("stroke-gradient", m_state.strokeGradient.get());
 292
 293 if (m_changeFlags & GraphicsContextState::StrokePatternChange)
 294 ts.dumpProperty("stroke-pattern", m_state.strokePattern.get());
 295
 296 if (m_changeFlags & GraphicsContextState::FillGradientChange)
 297 ts.dumpProperty("fill-gradient", m_state.fillGradient.get());
 298
 299 if (m_changeFlags & GraphicsContextState::FillPatternChange)
 300 ts.dumpProperty("fill-pattern", m_state.fillPattern.get());
 301
 302 if (m_changeFlags & GraphicsContextState::ShadowChange) {
 303 ts.dumpProperty("shadow-blur", m_state.shadowBlur);
 304 ts.dumpProperty("shadow-offset", m_state.shadowOffset);
 305 ts.dumpProperty("shadows-use-legacy-radius", m_state.shadowsUseLegacyRadius);
 306 }
 307
 308 if (m_changeFlags & GraphicsContextState::StrokeThicknessChange)
 309 ts.dumpProperty("stroke-thickness", m_state.strokeThickness);
 310
 311 if (m_changeFlags & GraphicsContextState::TextDrawingModeChange)
 312 ts.dumpProperty("text-drawing-mode", m_state.textDrawingMode);
 313
 314 if (m_changeFlags & GraphicsContextState::StrokeColorChange)
 315 ts.dumpProperty("stroke-color", m_state.strokeColor);
 316
 317 if (m_changeFlags & GraphicsContextState::FillColorChange)
 318 ts.dumpProperty("fill-color", m_state.fillColor);
 319
 320 if (m_changeFlags & GraphicsContextState::StrokeStyleChange)
 321 ts.dumpProperty("stroke-style", m_state.strokeStyle);
 322
 323 if (m_changeFlags & GraphicsContextState::FillRuleChange)
 324 ts.dumpProperty("fill-rule", m_state.fillRule);
 325
 326 if (m_changeFlags & GraphicsContextState::AlphaChange)
 327 ts.dumpProperty("alpha", m_state.alpha);
 328
 329 if (m_changeFlags & GraphicsContextState::CompositeOperationChange)
 330 ts.dumpProperty("composite-operator", m_state.compositeOperator);
 331
 332 if (m_changeFlags & GraphicsContextState::BlendModeChange)
 333 ts.dumpProperty("blend-mode", m_state.blendMode);
 334
 335 if (m_changeFlags & GraphicsContextState::ShouldAntialiasChange)
 336 ts.dumpProperty("should-antialias", m_state.shouldAntialias);
 337
 338 if (m_changeFlags & GraphicsContextState::ShouldSmoothFontsChange)
 339 ts.dumpProperty("should-smooth-fonts", m_state.shouldSmoothFonts);
 340
 341 if (m_changeFlags & GraphicsContextState::AntialiasedFontDilationEnabledChange)
 342 ts.dumpProperty("antialiased-font-dilation-enabled", m_state.antialiasedFontDilationEnabled);
 343
 344 if (m_changeFlags & GraphicsContextState::ShouldSubpixelQuantizeFontsChange)
 345 ts.dumpProperty("should-subpixel-quantize-fonts", m_state.shouldSubpixelQuantizeFonts);
 346
 347 if (m_changeFlags & GraphicsContextState::ShadowsIgnoreTransformsChange)
 348 ts.dumpProperty("shadows-ignore-transforms", m_state.shadowsIgnoreTransforms);
 349
 350 if (m_changeFlags & GraphicsContextState::DrawLuminanceMaskChange)
 351 ts.dumpProperty("draw-luminance-mask", m_state.drawLuminanceMask);
 352}
 353
 354TextStream& operator<<(TextStream& ts, const GraphicsContextStateChange& stateChange)
 355{
 356 stateChange.dump(ts);
 357 return ts;
 358}
 359
 360
101361GraphicsContext::GraphicsContext(PlatformGraphicsContext* platformGraphicsContext)
102362 : m_updatingControlTints(false)
103363 , m_transparencyCount(0)

Source/WebCore/platform/graphics/GraphicsContext.h

@@struct GraphicsContextState {
127127 {
128128 }
129129
 130 enum Change : uint32_t {
 131 NoChange = 0,
 132 StrokeGradientChange = 1 << 1,
 133 StrokePatternChange = 1 << 2,
 134 FillGradientChange = 1 << 3,
 135 FillPatternChange = 1 << 4,
 136 StrokeThicknessChange = 1 << 5,
 137 StrokeColorChange = 1 << 6,
 138 StrokeStyleChange = 1 << 7,
 139 FillColorChange = 1 << 8,
 140 FillRuleChange = 1 << 9,
 141 ShadowChange = 1 << 10,
 142 ShadowColorChange = 1 << 11,
 143 ShadowsIgnoreTransformsChange = 1 << 12,
 144 AlphaChange = 1 << 13,
 145 CompositeOperationChange = 1 << 14,
 146 BlendModeChange = 1 << 15,
 147 TextDrawingModeChange = 1 << 16,
 148 ShouldAntialiasChange = 1 << 17,
 149 ShouldSmoothFontsChange = 1 << 18,
 150 AntialiasedFontDilationEnabledChange = 1 << 19,
 151 ShouldSubpixelQuantizeFontsChange = 1 << 20,
 152 DrawLuminanceMaskChange = 1 << 21,
 153 ImageInterpolationQualityChange = 1 << 22,
 154 };
 155 typedef uint32_t StateChangeFlags;
 156
130157 RefPtr<Gradient> strokeGradient;
131158 RefPtr<Pattern> strokePattern;
132159

@@struct ImagePaintingOptions {
195222 bool m_useLowQualityScale;
196223};
197224
 225struct GraphicsContextStateChange {
 226 GraphicsContextStateChange() = default;
 227 GraphicsContextStateChange(const GraphicsContextState& state, GraphicsContextState::StateChangeFlags flags)
 228 : m_state(state)
 229 , m_changeFlags(flags)
 230 {
 231 }
 232
 233 GraphicsContextState::StateChangeFlags changesFromState(const GraphicsContextState&) const;
 234
 235 void accumulate(const GraphicsContextState&, GraphicsContextState::StateChangeFlags);
 236 void apply(GraphicsContext&) const;
 237
 238 void dump(TextStream&) const;
 239
 240 GraphicsContextState m_state;
 241 GraphicsContextState::StateChangeFlags m_changeFlags { 0 };
 242};
 243
 244TextStream& operator<<(TextStream&, const GraphicsContextStateChange&);
 245
 246
198247class GraphicsContext {
199248 WTF_MAKE_NONCOPYABLE(GraphicsContext); WTF_MAKE_FAST_ALLOCATED;
200249public:

Source/WebCore/platform/graphics/displaylists/DisplayList.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 "DisplayList.h"
 28
 29#include "Logging.h"
 30#include "TextStream.h"
 31#include <wtf/StdLibExtras.h>
 32
 33namespace WebCore {
 34namespace DisplayList {
 35
 36#if !defined(NDEBUG) || !LOG_DISABLED
 37WTF::CString DisplayList::description() const
 38{
 39 TextStream ts;
 40 ts << *this;
 41 return ts.release().utf8();
 42}
 43
 44void DisplayList::dump() const
 45{
 46 fprintf(stderr, "%s", description().data());
 47}
 48#endif
 49
 50void DisplayList::dump(TextStream& ts) const
 51{
 52 TextStream::GroupScope group(ts);
 53 ts << "display list";
 54
 55 size_t numItems = m_list.size();
 56 for (size_t i = 0; i < numItems; ++i) {
 57 TextStream::GroupScope scope(ts);
 58 ts << i << " " << m_list[i].get();
 59 }
 60 ts.startGroup();
 61 ts << "size in bytes: " << sizeInBytes();
 62 ts.endGroup();
 63}
 64
 65size_t DisplayList::sizeInBytes() const
 66{
 67 size_t result = 0;
 68 for (auto& ref : m_list) {
 69 switch (ref->type()) {
 70 case ItemType::Save:
 71 result += sizeof(downcast<Save>(ref.get()));
 72 break;
 73 case ItemType::Restore:
 74 result += sizeof(downcast<Restore>(ref.get()));
 75 break;
 76 case ItemType::Translate:
 77 result += sizeof(downcast<Translate>(ref.get()));
 78 break;
 79 case ItemType::Rotate:
 80 result += sizeof(downcast<Rotate>(ref.get()));
 81 break;
 82 case ItemType::Scale:
 83 result += sizeof(downcast<Scale>(ref.get()));
 84 break;
 85 case ItemType::ConcatenateCTM:
 86 result += sizeof(downcast<ConcatenateCTM>(ref.get()));
 87 break;
 88 case ItemType::SetState:
 89 result += sizeof(downcast<SetState>(ref.get()));
 90 break;
 91 case ItemType::SetLineCap:
 92 result += sizeof(downcast<SetLineCap>(ref.get()));
 93 break;
 94 case ItemType::SetLineDash:
 95 result += sizeof(downcast<SetLineDash>(ref.get()));
 96 break;
 97 case ItemType::SetLineJoin:
 98 result += sizeof(downcast<SetLineJoin>(ref.get()));
 99 break;
 100 case ItemType::SetMiterLimit:
 101 result += sizeof(downcast<SetMiterLimit>(ref.get()));
 102 break;
 103 case ItemType::ClearShadow:
 104 result += sizeof(downcast<ClearShadow>(ref.get()));
 105 break;
 106 case ItemType::Clip:
 107 result += sizeof(downcast<Clip>(ref.get()));
 108 break;
 109 case ItemType::ClipOut:
 110 result += sizeof(downcast<ClipOut>(ref.get()));
 111 break;
 112 case ItemType::ClipOutToPath:
 113 result += sizeof(downcast<ClipOutToPath>(ref.get()));
 114 break;
 115 case ItemType::ClipPath:
 116 result += sizeof(downcast<ClipPath>(ref.get()));
 117 break;
 118 case ItemType::ClipConvexPolygon:
 119 result += sizeof(downcast<ClipConvexPolygon>(ref.get()));
 120 break;
 121 case ItemType::DrawGlyphs:
 122 result += sizeof(downcast<DrawGlyphs>(ref.get()));
 123 break;
 124 case ItemType::DrawImage:
 125 result += sizeof(downcast<DrawImage>(ref.get()));
 126 break;
 127 case ItemType::DrawTiledImage:
 128 result += sizeof(downcast<DrawTiledImage>(ref.get()));
 129 break;
 130 case ItemType::DrawTiledScaledImage:
 131 result += sizeof(downcast<DrawTiledScaledImage>(ref.get()));
 132 break;
 133 case ItemType::DrawNativeImage:
 134 result += sizeof(downcast<DrawNativeImage>(ref.get()));
 135 break;
 136 case ItemType::DrawPattern:
 137 result += sizeof(downcast<DrawPattern>(ref.get()));
 138 break;
 139 case ItemType::DrawRect:
 140 result += sizeof(downcast<DrawRect>(ref.get()));
 141 break;
 142 case ItemType::DrawLine:
 143 result += sizeof(downcast<DrawLine>(ref.get()));
 144 break;
 145 case ItemType::DrawLinesForText:
 146 result += sizeof(downcast<DrawLinesForText>(ref.get()));
 147 break;
 148 case ItemType::DrawLineForDocumentMarker:
 149 result += sizeof(downcast<DrawLineForDocumentMarker>(ref.get()));
 150 break;
 151 case ItemType::DrawEllipse:
 152 result += sizeof(downcast<DrawEllipse>(ref.get()));
 153 break;
 154 case ItemType::DrawConvexPolygon:
 155 result += sizeof(downcast<DrawConvexPolygon>(ref.get()));
 156 break;
 157 case ItemType::DrawPath:
 158 result += sizeof(downcast<DrawPath>(ref.get()));
 159 break;
 160 case ItemType::DrawFocusRingPath:
 161 result += sizeof(downcast<DrawFocusRingPath>(ref.get()));
 162 break;
 163 case ItemType::DrawFocusRingRects:
 164 result += sizeof(downcast<DrawFocusRingRects>(ref.get()));
 165 break;
 166 case ItemType::FillRect:
 167 result += sizeof(downcast<FillRect>(ref.get()));
 168 break;
 169 case ItemType::FillRectWithColor:
 170 result += sizeof(downcast<FillRectWithColor>(ref.get()));
 171 break;
 172 case ItemType::FillRectWithGradient:
 173 result += sizeof(downcast<FillRectWithGradient>(ref.get()));
 174 break;
 175 case ItemType::FillCompositedRect:
 176 result += sizeof(downcast<FillCompositedRect>(ref.get()));
 177 break;
 178 case ItemType::FillRoundedRect:
 179 result += sizeof(downcast<FillRoundedRect>(ref.get()));
 180 break;
 181 case ItemType::FillRectWithRoundedHole:
 182 result += sizeof(downcast<FillRectWithRoundedHole>(ref.get()));
 183 break;
 184 case ItemType::FillPath:
 185 result += sizeof(downcast<FillPath>(ref.get()));
 186 break;
 187 case ItemType::FillEllipse:
 188 result += sizeof(downcast<FillEllipse>(ref.get()));
 189 break;
 190 case ItemType::StrokeRect:
 191 result += sizeof(downcast<StrokeRect>(ref.get()));
 192 break;
 193 case ItemType::StrokePath:
 194 result += sizeof(downcast<StrokePath>(ref.get()));
 195 break;
 196 case ItemType::StrokeEllipse:
 197 result += sizeof(downcast<StrokeEllipse>(ref.get()));
 198 break;
 199 case ItemType::ClearRect:
 200 result += sizeof(downcast<ClearRect>(ref.get()));
 201 break;
 202 case ItemType::BeginTransparencyLayer:
 203 result += sizeof(downcast<BeginTransparencyLayer>(ref.get()));
 204 break;
 205 case ItemType::EndTransparencyLayer:
 206 result += sizeof(downcast<EndTransparencyLayer>(ref.get()));
 207 break;
 208 case ItemType::ApplyStrokePattern:
 209 result += sizeof(downcast<ApplyStrokePattern>(ref.get()));
 210 break;
 211 case ItemType::ApplyFillPattern:
 212 result += sizeof(downcast<ApplyFillPattern>(ref.get()));
 213 break;
 214 case ItemType::ApplyDeviceScaleFactor:
 215 result += sizeof(downcast<ApplyDeviceScaleFactor>(ref.get()));
 216 break;
 217 }
 218 }
 219 return result;
 220}
 221
 222} // namespace DisplayList
 223
 224TextStream& operator<<(TextStream& ts, const DisplayList::DisplayList& displayList)
 225{
 226 displayList.dump(ts);
 227 return ts;
 228}
 229
 230} // namespace WebCore

Source/WebCore/platform/graphics/displaylists/DisplayList.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#ifndef DisplayList_h
 27#define DisplayList_h
 28
 29#include "DisplayListItems.h"
 30#include <wtf/FastMalloc.h>
 31#include <wtf/Noncopyable.h>
 32#include <wtf/text/WTFString.h>
 33
 34namespace WebCore {
 35
 36class FloatRect;
 37class GraphicsContext;
 38class TextStream;
 39
 40namespace DisplayList {
 41
 42class DisplayList {
 43 WTF_MAKE_NONCOPYABLE(DisplayList);
 44 friend class Recorder;
 45public:
 46 DisplayList() = default;
 47 DisplayList(DisplayList&&) = default;
 48
 49 DisplayList& operator=(DisplayList&&) = default;
 50
 51 void dump(TextStream&) const;
 52
 53 const Vector<Ref<Item>>& list() const { return m_list; }
 54 Item& itemAt(size_t index)
 55 {
 56 ASSERT(index < m_list.size());
 57 return m_list[index].get();
 58 }
 59
 60 void clear() { m_list.clear(); }
 61 size_t size() const { return m_list.size(); }
 62
 63 void removeItemsFromIndex(size_t index)
 64 {
 65 m_list.resize(index);
 66 }
 67
 68 size_t sizeInBytes() const;
 69
 70#if !defined(NDEBUG) || !LOG_DISABLED
 71 WTF::CString description() const;
 72 void dump() const;
 73#endif
 74
 75private:
 76 Item& append(Ref<Item>&& item)
 77 {
 78 m_list.append(WTFMove(item));
 79 return m_list.last().get();
 80 }
 81
 82 Vector<Ref<Item>>& list() { return m_list; }
 83
 84 Vector<Ref<Item>> m_list;
 85};
 86
 87} // DisplayList
 88
 89TextStream& operator<<(TextStream&, const DisplayList::DisplayList&);
 90
 91} // WebCore
 92
 93using WebCore::DisplayList::DisplayList;
 94
 95#endif /* DisplayList_h */

Source/WebCore/platform/graphics/displaylists/DisplayListItems.cpp

 1/*
 2 * Copyright (C) 2015 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 "DisplayListItems.h"
 28
 29#include "FontCascade.h"
 30#include "TextStream.h"
 31
 32namespace WebCore {
 33namespace DisplayList {
 34
 35// Should match RenderTheme::platformFocusRingWidth()
 36static const float platformFocusRingWidth = 3;
 37
 38#if !defined(NDEBUG) || !LOG_DISABLED
 39WTF::CString Item::description() const
 40{
 41 TextStream ts;
 42 ts << *this;
 43 return ts.release().utf8();
 44}
 45#endif
 46
 47static TextStream& operator<<(TextStream& ts, const DrawingItem& item)
 48{
 49 ts.startGroup();
 50 ts << "extent ";
 51 if (item.extentKnown())
 52 ts << item.extent();
 53 else
 54 ts << "unknown";
 55
 56 ts.endGroup();
 57 return ts;
 58}
 59
 60void Save::apply(GraphicsContext& context) const
 61{
 62 context.save();
 63}
 64
 65static TextStream& operator<<(TextStream& ts, const Save& item)
 66{
 67 ts.dumpProperty("restore-index", item.restoreIndex());
 68 return ts;
 69}
 70
 71void Restore::apply(GraphicsContext& context) const
 72{
 73 context.restore();
 74}
 75
 76void Translate::apply(GraphicsContext& context) const
 77{
 78 context.translate(m_x, m_y);
 79}
 80
 81static TextStream& operator<<(TextStream& ts, const Translate& item)
 82{
 83 ts.dumpProperty("x", item.x());
 84 ts.dumpProperty("y", item.y());
 85
 86 return ts;
 87}
 88
 89void Rotate::apply(GraphicsContext& context) const
 90{
 91 context.rotate(m_angle);
 92}
 93
 94static TextStream& operator<<(TextStream& ts, const Rotate& item)
 95{
 96 ts.dumpProperty("angle", item.angle());
 97
 98 return ts;
 99}
 100
 101void Scale::apply(GraphicsContext& context) const
 102{
 103 context.scale(m_size);
 104}
 105
 106static TextStream& operator<<(TextStream& ts, const Scale& item)
 107{
 108 ts.dumpProperty("size", item.amount());
 109
 110 return ts;
 111}
 112
 113ConcatenateCTM::ConcatenateCTM(const AffineTransform& transform)
 114 : Item(ItemType::ConcatenateCTM)
 115 , m_transform(transform)
 116{
 117}
 118
 119void ConcatenateCTM::apply(GraphicsContext& context) const
 120{
 121 context.concatCTM(m_transform);
 122}
 123
 124static TextStream& operator<<(TextStream& ts, const ConcatenateCTM& item)
 125{
 126 ts.dumpProperty("ctm", item.transform());
 127
 128 return ts;
 129}
 130
 131void SetState::apply(GraphicsContext& context) const
 132{
 133 m_state.apply(context);
 134}
 135
 136void SetState::accumulate(const GraphicsContextState& state, GraphicsContextState::StateChangeFlags flags)
 137{
 138 m_state.accumulate(state, flags);
 139}
 140
 141static TextStream& operator<<(TextStream& ts, const SetState& state)
 142{
 143 ts << state.state();
 144 return ts;
 145}
 146
 147void SetLineCap::apply(GraphicsContext& context) const
 148{
 149 context.setLineCap(m_lineCap);
 150}
 151
 152static TextStream& operator<<(TextStream& ts, const SetLineCap& lineCap)
 153{
 154 ts.dumpProperty("line-cap", lineCap.lineCap());
 155 return ts;
 156}
 157
 158void SetLineDash::apply(GraphicsContext& context) const
 159{
 160 context.setLineDash(m_dashArray, m_dashOffset);
 161}
 162
 163static TextStream& operator<<(TextStream& ts, const SetLineDash& lineDash)
 164{
 165 ts.dumpProperty("dash-array", lineDash.dashArray());
 166 ts.dumpProperty("dash-offset", lineDash.dashOffset());
 167 return ts;
 168}
 169
 170void SetLineJoin::apply(GraphicsContext& context) const
 171{
 172 context.setLineJoin(m_lineJoin);
 173}
 174
 175static TextStream& operator<<(TextStream& ts, const SetLineJoin& lineJoin)
 176{
 177 ts.dumpProperty("line-join", lineJoin.lineJoin());
 178 return ts;
 179}
 180
 181void SetMiterLimit::apply(GraphicsContext& context) const
 182{
 183 context.setMiterLimit(m_miterLimit);
 184}
 185
 186static TextStream& operator<<(TextStream& ts, const SetMiterLimit& miterLimit)
 187{
 188 ts.dumpProperty("mitre-limit", miterLimit.miterLimit());
 189 return ts;
 190}
 191
 192void ClearShadow::apply(GraphicsContext& context) const
 193{
 194 context.clearShadow();
 195}
 196
 197void Clip::apply(GraphicsContext& context) const
 198{
 199 context.clip(m_rect);
 200}
 201
 202static TextStream& operator<<(TextStream& ts, const Clip& item)
 203{
 204 ts.dumpProperty("rect", item.rect());
 205 return ts;
 206}
 207
 208void ClipOut::apply(GraphicsContext& context) const
 209{
 210 context.clipOut(m_rect);
 211}
 212
 213static TextStream& operator<<(TextStream& ts, const ClipOut& item)
 214{
 215 ts.dumpProperty("rect", item.rect());
 216 return ts;
 217}
 218
 219void ClipOutToPath::apply(GraphicsContext& context) const
 220{
 221 context.clipOut(m_path);
 222}
 223
 224static TextStream& operator<<(TextStream& ts, const ClipOutToPath&)
 225{
 226// ts.dumpProperty("path", item.path()); // FIXME: path logging.
 227 return ts;
 228}
 229
 230void ClipPath::apply(GraphicsContext& context) const
 231{
 232 context.clipPath(m_path, m_windRule);
 233}
 234
 235static TextStream& operator<<(TextStream& ts, const ClipPath& item)
 236{
 237// ts.dumpProperty("path", item.path()); // FIXME: path logging.
 238 ts.dumpProperty("wind-rule", item.windRule());
 239 return ts;
 240}
 241
 242ClipConvexPolygon::ClipConvexPolygon(size_t numberOfPoints, const FloatPoint* points, bool antialiased)
 243 : Item(ItemType::ClipConvexPolygon)
 244 , m_antialias(antialiased)
 245{
 246 for (size_t i = 0; i < numberOfPoints; ++i)
 247 m_points.append(points[i]);
 248}
 249
 250void ClipConvexPolygon::apply(GraphicsContext& context) const
 251{
 252 context.clipConvexPolygon(m_points.size(), m_points.data(), m_antialias);
 253}
 254
 255static TextStream& operator<<(TextStream& ts, const ClipConvexPolygon& item)
 256{
 257 ts.dumpProperty("points", item.points());
 258 ts.dumpProperty("antialias", item.antialias());
 259 return ts;
 260}
 261
 262DrawGlyphs::DrawGlyphs(const Font& font, const GlyphBufferGlyph* glyphs, const GlyphBufferAdvance* advances, unsigned count, const FloatPoint& blockLocation, const FloatSize& localAnchor, FontSmoothingMode smoothingMode)
 263 : DrawingItem(ItemType::DrawGlyphs)
 264 , m_font(const_cast<Font&>(font))
 265 , m_blockLocation(blockLocation)
 266 , m_localAnchor(localAnchor)
 267 , m_smoothingMode(smoothingMode)
 268{
 269 m_glyphs.reserveInitialCapacity(count);
 270 m_advances.reserveInitialCapacity(count);
 271 for (unsigned i = 0; i < count; ++i) {
 272 m_glyphs.uncheckedAppend(glyphs[i]);
 273 m_advances.uncheckedAppend(advances[i]);
 274 }
 275 computeBounds();
 276}
 277
 278inline GlyphBuffer DrawGlyphs::generateGlyphBuffer() const
 279{
 280 GlyphBuffer result;
 281 for (unsigned i = 0; i < m_glyphs.size(); ++i)
 282 result.add(m_glyphs[i], &m_font.get(), m_advances[i]);
 283 return result;
 284}
 285
 286void DrawGlyphs::apply(GraphicsContext&) const
 287{
 288 // FIXME: implement.
 289 UNUSED_PARAM(m_smoothingMode);
 290}
 291
 292void DrawGlyphs::computeBounds()
 293{
 294 // FIXME: This code doesn't actually take the extents of the glyphs into consideration. It assumes that
 295 // the glyph lies entirely within its (ascent+descent x advance) rect.
 296 float ascent = m_font->fontMetrics().floatAscent();
 297 float descent = m_font->fontMetrics().floatDescent();
 298 FloatPoint current = toFloatPoint(localAnchor());
 299 for (size_t i = 0; i < m_glyphs.size(); ++i) {
 300 GlyphBufferAdvance advance = m_advances[i];
 301 FloatRect glyphRect = FloatRect(current.x(), current.y() - ascent, advance.width(), ascent + descent);
 302 m_bounds.unite(glyphRect);
 303
 304 current += FloatSize(advance);
 305 }
 306}
 307
 308Optional<FloatRect> DrawGlyphs::localBounds(const GraphicsContext&) const
 309{
 310 FloatRect localBounds = m_bounds;
 311 localBounds.move(m_blockLocation.x(), m_blockLocation.y());
 312 return localBounds;
 313}
 314
 315static TextStream& operator<<(TextStream& ts, const DrawGlyphs& item)
 316{
 317 ts << static_cast<const DrawingItem&>(item);
 318 // FIXME: dump more stuff.
 319 ts.dumpProperty("block-location", item.blockLocation());
 320 ts.dumpProperty("local-anchor", item.localAnchor());
 321 ts.dumpProperty("anchor-point", item.anchorPoint());
 322 ts.dumpProperty("length", item.glyphs().size());
 323
 324 return ts;
 325}
 326
 327DrawImage::DrawImage(Image& image, const FloatRect& destination, const FloatRect& source, const ImagePaintingOptions& imagePaintingOptions)
 328 : DrawingItem(ItemType::DrawImage)
 329 , m_image(image)
 330 , m_destination(destination)
 331 , m_source(source)
 332 , m_imagePaintingOptions(imagePaintingOptions)
 333{
 334}
 335
 336void DrawImage::apply(GraphicsContext& context) const
 337{
 338 context.drawImage(m_image.get(), m_destination, m_source, m_imagePaintingOptions);
 339}
 340
 341static TextStream& operator<<(TextStream& ts, const DrawImage& item)
 342{
 343 ts << static_cast<const DrawingItem&>(item);
 344 ts.dumpProperty("image", item.image());
 345 ts.dumpProperty("source-rect", item.source());
 346 ts.dumpProperty("dest-rect", item.destination());
 347 return ts;
 348}
 349
 350DrawTiledImage::DrawTiledImage(Image& image, const FloatRect& destination, const FloatPoint& source, const FloatSize& tileSize, const FloatSize& spacing, const ImagePaintingOptions& imagePaintingOptions)
 351 : DrawingItem(ItemType::DrawTiledImage)
 352 , m_image(image)
 353 , m_destination(destination)
 354 , m_source(source)
 355 , m_tileSize(tileSize)
 356 , m_spacing(spacing)
 357 , m_imagePaintingOptions(imagePaintingOptions)
 358{
 359}
 360
 361void DrawTiledImage::apply(GraphicsContext& context) const
 362{
 363 context.drawTiledImage(m_image.get(), m_destination, m_source, m_tileSize, m_spacing, m_imagePaintingOptions);
 364}
 365
 366static TextStream& operator<<(TextStream& ts, const DrawTiledImage& item)
 367{
 368 ts << static_cast<const DrawingItem&>(item);
 369 ts.dumpProperty("image", item.image());
 370 ts.dumpProperty("source-point", item.source());
 371 ts.dumpProperty("dest-rect", item.destination());
 372 ts.dumpProperty("tile-size", item.tileSize());
 373 ts.dumpProperty("spacing", item.spacing());
 374 return ts;
 375}
 376
 377DrawTiledScaledImage::DrawTiledScaledImage(Image& image, const FloatRect& destination, const FloatRect& source, const FloatSize& tileScaleFactor, Image::TileRule hRule, Image::TileRule vRule, const ImagePaintingOptions& imagePaintingOptions)
 378 : DrawingItem(ItemType::DrawTiledScaledImage)
 379 , m_image(image)
 380 , m_destination(destination)
 381 , m_source(source)
 382 , m_tileScaleFactor(tileScaleFactor)
 383 , m_hRule(hRule)
 384 , m_vRule(vRule)
 385 , m_imagePaintingOptions(imagePaintingOptions)
 386{
 387}
 388
 389void DrawTiledScaledImage::apply(GraphicsContext& context) const
 390{
 391 context.drawTiledImage(m_image.get(), m_destination, m_source, m_tileScaleFactor, m_hRule, m_vRule, m_imagePaintingOptions);
 392}
 393
 394static TextStream& operator<<(TextStream& ts, const DrawTiledScaledImage& item)
 395{
 396 ts << static_cast<const DrawingItem&>(item);
 397 ts.dumpProperty("image", item.image());
 398 ts.dumpProperty("source-rect", item.source());
 399 ts.dumpProperty("dest-rect", item.destination());
 400 return ts;
 401}
 402
 403DrawNativeImage::DrawNativeImage(PassNativeImagePtr imagePtr, const FloatSize& imageSize, const FloatRect& destRect, const FloatRect& srcRect, CompositeOperator op, BlendMode blendMode, ImageOrientation orientation)
 404 : DrawingItem(ItemType::DrawNativeImage)
 405 , m_imagePtr(imagePtr)
 406 , m_imageSize(imageSize)
 407 , m_destination(destRect)
 408 , m_srcRect(srcRect)
 409 , m_op(op)
 410 , m_blendMode(blendMode)
 411 , m_orientation(orientation)
 412{
 413}
 414
 415void DrawNativeImage::apply(GraphicsContext& context) const
 416{
 417#if USE(CG)
 418 auto imagePtr = m_imagePtr.get();
 419#endif
 420 context.drawNativeImage(imagePtr, m_imageSize, m_destination, m_srcRect, m_op, m_blendMode, m_orientation);
 421}
 422
 423static TextStream& operator<<(TextStream& ts, const DrawNativeImage& item)
 424{
 425 ts << static_cast<const DrawingItem&>(item);
 426 // FIXME: dump more stuff.
 427 ts.dumpProperty("source-rect", item.source());
 428 ts.dumpProperty("dest-rect", item.destination());
 429 return ts;
 430}
 431
 432DrawPattern::DrawPattern(Image& image, const FloatRect& tileRect, const AffineTransform& patternTransform, const FloatPoint& phase, const FloatSize& spacing, CompositeOperator op, const FloatRect& destRect, BlendMode blendMode)
 433 : DrawingItem(ItemType::DrawPattern)
 434 , m_image(image)
 435 , m_patternTransform(patternTransform)
 436 , m_tileRect(tileRect)
 437 , m_destination(destRect)
 438 , m_phase(phase)
 439 , m_spacing(spacing)
 440 , m_op(op)
 441 , m_blendMode(blendMode)
 442{
 443}
 444
 445void DrawPattern::apply(GraphicsContext& context) const
 446{
 447 context.drawPattern(m_image.get(), m_tileRect, m_patternTransform, m_phase, m_spacing, m_op, m_destination, m_blendMode);
 448}
 449
 450static TextStream& operator<<(TextStream& ts, const DrawPattern& item)
 451{
 452 ts << static_cast<const DrawingItem&>(item);
 453 ts.dumpProperty("image", item.image());
 454 ts.dumpProperty("pattern-transform", item.patternTransform());
 455 ts.dumpProperty("tile-rect", item.tileRect());
 456 ts.dumpProperty("dest-rect", item.destRect());
 457 ts.dumpProperty("phase", item.phase());
 458 ts.dumpProperty("spacing", item.spacing());
 459 return ts;
 460}
 461
 462void DrawRect::apply(GraphicsContext& context) const
 463{
 464 context.drawRect(m_rect, m_borderThickness);
 465}
 466
 467static TextStream& operator<<(TextStream& ts, const DrawRect& item)
 468{
 469 ts << static_cast<const DrawingItem&>(item);
 470 ts.dumpProperty("rect", item.rect());
 471 ts.dumpProperty("border-thickness", item.borderThickness());
 472 return ts;
 473}
 474
 475Optional<FloatRect> DrawLine::localBounds(const GraphicsContext&) const
 476{
 477 FloatRect bounds;
 478 bounds.fitToPoints(m_point1, m_point2);
 479 return bounds;
 480}
 481
 482void DrawLine::apply(GraphicsContext& context) const
 483{
 484 context.drawLine(m_point1, m_point2);
 485}
 486
 487static TextStream& operator<<(TextStream& ts, const DrawLine& item)
 488{
 489 ts << static_cast<const DrawingItem&>(item);
 490 ts.dumpProperty("point-1", item.point1());
 491 ts.dumpProperty("point-2", item.point2());
 492 return ts;
 493}
 494
 495void DrawLinesForText::apply(GraphicsContext& context) const
 496{
 497 context.drawLinesForText(point(), m_widths, m_printing, m_doubleLines);
 498}
 499
 500Optional<FloatRect> DrawLinesForText::localBounds(const GraphicsContext&) const
 501{
 502 // This function needs to return a value equal to or enclosing what GraphicsContext::computeLineBoundsAndAntialiasingModeForText() returns.
 503
 504 if (!m_widths.size())
 505 return FloatRect();
 506
 507 FloatRect result(point(), FloatSize(m_widths.last(), m_strokeWidth));
 508 result.inflate(1); // Account for pixel snapping. FIXME: This isn't perfect, as it doesn't take the CTM into account.
 509 return result;
 510}
 511
 512static TextStream& operator<<(TextStream& ts, const DrawLinesForText& item)
 513{
 514 ts << static_cast<const DrawingItem&>(item);
 515 ts.dumpProperty("block-location", item.blockLocation());
 516 ts.dumpProperty("local-anchor", item.localAnchor());
 517 ts.dumpProperty("point", item.point());
 518 ts.dumpProperty("double", item.doubleLines());
 519 ts.dumpProperty("widths", item.widths());
 520 ts.dumpProperty("is-printing", item.isPrinting());
 521 ts.dumpProperty("double", item.doubleLines());
 522 return ts;
 523}
 524
 525void DrawLineForDocumentMarker::apply(GraphicsContext& context) const
 526{
 527 context.drawLineForDocumentMarker(m_point, m_width, m_style);
 528}
 529
 530Optional<FloatRect> DrawLineForDocumentMarker::localBounds(const GraphicsContext&) const
 531{
 532 // This function needs to return a value equal to or enclosing what GraphicsContext::drawLineForDocumentMarker() returns.
 533
 534 FloatRect result(m_point, FloatSize(m_width, cMisspellingLineThickness));
 535 result.inflate(cMisspellingLineThickness); // Account for "misspelling dot" snapping.
 536 return result;
 537}
 538
 539static TextStream& operator<<(TextStream& ts, const DrawLineForDocumentMarker& item)
 540{
 541 ts << static_cast<const DrawingItem&>(item);
 542 ts.dumpProperty("point", item.point());
 543 ts.dumpProperty("width", item.width());
 544 return ts;
 545}
 546
 547void DrawEllipse::apply(GraphicsContext& context) const
 548{
 549 context.drawEllipse(m_rect);
 550}
 551
 552static TextStream& operator<<(TextStream& ts, const DrawEllipse& item)
 553{
 554 ts.dumpProperty("rect", item.rect());
 555 return ts;
 556}
 557
 558// FIXME: share this code.
 559void addConvexPolygonToPath(Path& path, size_t numPoints, const FloatPoint* points)
 560{
 561 ASSERT(numPoints > 0);
 562
 563 path.moveTo(points[0]);
 564 for (size_t i = 1; i < numPoints; ++i)
 565 path.addLineTo(points[i]);
 566 path.closeSubpath();
 567}
 568
 569DrawConvexPolygon::DrawConvexPolygon(size_t numberOfPoints, const FloatPoint* points, bool antialiased)
 570 : DrawingItem(ItemType::DrawConvexPolygon)
 571 , m_antialiased(antialiased)
 572{
 573 for (size_t i = 0; i < numberOfPoints; ++i)
 574 m_points.append(points[i]);
 575}
 576
 577Optional<FloatRect> DrawConvexPolygon::localBounds(const GraphicsContext&) const
 578{
 579 FloatRect result;
 580 for (auto& point : m_points)
 581 result.extend(point);
 582 result.inflate(m_antialiased ? 1 : 0); // Account for antialiasing
 583 return result;
 584}
 585
 586void DrawConvexPolygon::apply(GraphicsContext& context) const
 587{
 588 context.drawConvexPolygon(m_points.size(), m_points.data(), m_antialiased);
 589}
 590
 591static TextStream& operator<<(TextStream& ts, const DrawConvexPolygon& item)
 592{
 593 ts << static_cast<const DrawingItem&>(item);
 594 ts.dumpProperty("points", item.points());
 595 ts.dumpProperty("antialiased", item.antialiased());
 596 return ts;
 597}
 598
 599void DrawPath::apply(GraphicsContext& context) const
 600{
 601 context.drawPath(m_path);
 602}
 603
 604static TextStream& operator<<(TextStream& ts, const DrawPath& item)
 605{
 606 ts << static_cast<const DrawingItem&>(item);
 607// ts.dumpProperty("path", item.path()); // FIXME: add logging for paths.
 608 return ts;
 609}
 610
 611void DrawFocusRingPath::apply(GraphicsContext& context) const
 612{
 613 context.drawFocusRing(m_path, m_width, m_offset, m_color);
 614}
 615
 616Optional<FloatRect> DrawFocusRingPath::localBounds(const GraphicsContext&) const
 617{
 618 FloatRect result = m_path.fastBoundingRect();
 619 result.inflate(platformFocusRingWidth);
 620 return result;
 621}
 622
 623static TextStream& operator<<(TextStream& ts, const DrawFocusRingPath& item)
 624{
 625 ts << static_cast<const DrawingItem&>(item);
 626// ts.dumpProperty("path", item.path()); // FIXME: add logging for paths.
 627 ts.dumpProperty("width", item.width());
 628 ts.dumpProperty("offset", item.offset());
 629 ts.dumpProperty("color", item.color());
 630 return ts;
 631}
 632
 633void DrawFocusRingRects::apply(GraphicsContext& context) const
 634{
 635 context.drawFocusRing(m_rects, m_width, m_offset, m_color);
 636}
 637
 638Optional<FloatRect> DrawFocusRingRects::localBounds(const GraphicsContext&) const
 639{
 640 FloatRect result;
 641 for (auto& rect : m_rects)
 642 result.unite(rect);
 643 result.inflate(platformFocusRingWidth);
 644 return result;
 645}
 646
 647static TextStream& operator<<(TextStream& ts, const DrawFocusRingRects& item)
 648{
 649 ts << static_cast<const DrawingItem&>(item);
 650 ts.dumpProperty("rects", item.rects());
 651 ts.dumpProperty("width", item.width());
 652 ts.dumpProperty("offset", item.offset());
 653 ts.dumpProperty("color", item.color());
 654 return ts;
 655}
 656
 657void FillRect::apply(GraphicsContext& context) const
 658{
 659 context.fillRect(m_rect);
 660}
 661
 662static TextStream& operator<<(TextStream& ts, const FillRect& item)
 663{
 664 ts << static_cast<const DrawingItem&>(item);
 665 ts.dumpProperty("rect", item.rect());
 666 return ts;
 667}
 668
 669void FillRectWithColor::apply(GraphicsContext& context) const
 670{
 671 context.fillRect(m_rect, m_color);
 672}
 673
 674static TextStream& operator<<(TextStream& ts, const FillRectWithColor& item)
 675{
 676 ts << static_cast<const DrawingItem&>(item);
 677 ts.dumpProperty("rect", item.rect());
 678 ts.dumpProperty("color", item.color());
 679 return ts;
 680}
 681
 682void FillRectWithGradient::apply(GraphicsContext& context) const
 683{
 684 context.fillRect(m_rect, m_gradient.get());
 685}
 686
 687static TextStream& operator<<(TextStream& ts, const FillRectWithGradient& item)
 688{
 689 ts << static_cast<const DrawingItem&>(item);
 690 // FIXME: log gradient.
 691 ts.dumpProperty("rect", item.rect());
 692 return ts;
 693}
 694
 695void FillCompositedRect::apply(GraphicsContext& context) const
 696{
 697 context.fillRect(m_rect, m_color, m_op, m_blendMode);
 698}
 699
 700static TextStream& operator<<(TextStream& ts, const FillCompositedRect& item)
 701{
 702 ts << static_cast<const DrawingItem&>(item);
 703 ts.dumpProperty("rect", item.rect());
 704 ts.dumpProperty("color", item.color());
 705 ts.dumpProperty("composite-operation", item.compositeOperator());
 706 ts.dumpProperty("blend-mode", item.blendMode());
 707 return ts;
 708}
 709
 710void FillRoundedRect::apply(GraphicsContext& context) const
 711{
 712 context.fillRoundedRect(m_rect, m_color, m_blendMode);
 713}
 714
 715static TextStream& operator<<(TextStream& ts, const FillRoundedRect& item)
 716{
 717 ts << static_cast<const DrawingItem&>(item);
 718 ts.dumpProperty("rect", item.roundedRect());
 719 ts.dumpProperty("color", item.color());
 720 ts.dumpProperty("blend-mode", item.blendMode());
 721 return ts;
 722}
 723
 724void FillRectWithRoundedHole::apply(GraphicsContext& context) const
 725{
 726 context.fillRectWithRoundedHole(m_rect, m_roundedHoleRect, m_color);
 727}
 728
 729static TextStream& operator<<(TextStream& ts, const FillRectWithRoundedHole& item)
 730{
 731 ts << static_cast<const DrawingItem&>(item);
 732 ts.dumpProperty("rect", item.rect());
 733 ts.dumpProperty("rounded-hole-rect", item.roundedHoleRect());
 734 ts.dumpProperty("color", item.color());
 735 return ts;
 736}
 737
 738void FillPath::apply(GraphicsContext& context) const
 739{
 740 context.fillPath(m_path);
 741}
 742
 743static TextStream& operator<<(TextStream& ts, const FillPath& item)
 744{
 745 ts << static_cast<const DrawingItem&>(item);
 746// ts.dumpProperty("path", item.path()); // FIXME: path logging.
 747 return ts;
 748}
 749
 750void FillEllipse::apply(GraphicsContext& context) const
 751{
 752 context.fillEllipse(m_rect);
 753}
 754
 755static TextStream& operator<<(TextStream& ts, const FillEllipse& item)
 756{
 757 ts << static_cast<const DrawingItem&>(item);
 758 ts.dumpProperty("rect", item.rect());
 759 return ts;
 760}
 761
 762Optional<FloatRect> StrokeRect::localBounds(const GraphicsContext&) const
 763{
 764 FloatRect bounds = m_rect;
 765 bounds.expand(m_lineWidth, m_lineWidth);
 766 return bounds;
 767}
 768
 769void StrokeRect::apply(GraphicsContext& context) const
 770{
 771 context.strokeRect(m_rect, m_lineWidth);
 772}
 773
 774static TextStream& operator<<(TextStream& ts, const StrokeRect& item)
 775{
 776 ts << static_cast<const DrawingItem&>(item);
 777 ts.dumpProperty("rect", item.rect());
 778 ts.dumpProperty("line-width", item.lineWidth());
 779 return ts;
 780}
 781
 782Optional<FloatRect> StrokePath::localBounds(const GraphicsContext& context) const
 783{
 784 // FIXME: Need to take stroke thickness into account correctly, via CGPathByStrokingPath().
 785 float strokeThickness = context.strokeThickness();
 786
 787 FloatRect bounds = m_path.boundingRect();
 788 bounds.expand(strokeThickness, strokeThickness);
 789 bounds.moveBy(m_blockLocation);
 790 return bounds;
 791}
 792
 793void StrokePath::apply(GraphicsContext& context) const
 794{
 795 FloatSize offset = toFloatSize(m_blockLocation);
 796 m_path.translate(offset);
 797 context.strokePath(m_path);
 798 m_path.translate(-offset);
 799}
 800
 801static TextStream& operator<<(TextStream& ts, const StrokePath& item)
 802{
 803 ts << static_cast<const DrawingItem&>(item);
 804 ts.dumpProperty("block-location", item.blockLocation());
 805// ts.dumpProperty("path", item.path()); // FIXME: path logging.
 806 return ts;
 807}
 808
 809Optional<FloatRect> StrokeEllipse::localBounds(const GraphicsContext& context) const
 810{
 811 float strokeThickness = context.strokeThickness();
 812
 813 FloatRect bounds = m_rect;
 814 bounds.expand(strokeThickness, strokeThickness);
 815 return bounds;
 816}
 817
 818void StrokeEllipse::apply(GraphicsContext& context) const
 819{
 820 context.strokeEllipse(m_rect);
 821}
 822
 823static TextStream& operator<<(TextStream& ts, const StrokeEllipse& item)
 824{
 825 ts << static_cast<const DrawingItem&>(item);
 826 ts.dumpProperty("rect", item.rect());
 827 return ts;
 828}
 829
 830void ClearRect::apply(GraphicsContext& context) const
 831{
 832 context.clearRect(m_rect);
 833}
 834
 835static TextStream& operator<<(TextStream& ts, const ClearRect& item)
 836{
 837 ts << static_cast<const DrawingItem&>(item);
 838 ts.dumpProperty("rect", item.rect());
 839 return ts;
 840}
 841
 842void BeginTransparencyLayer::apply(GraphicsContext& context) const
 843{
 844 context.beginTransparencyLayer(m_opacity);
 845}
 846
 847static TextStream& operator<<(TextStream& ts, const BeginTransparencyLayer& item)
 848{
 849 ts << static_cast<const DrawingItem&>(item);
 850 ts.dumpProperty("opacity", item.opacity());
 851 return ts;
 852}
 853
 854void EndTransparencyLayer::apply(GraphicsContext& context) const
 855{
 856 context.endTransparencyLayer();
 857}
 858
 859void ApplyStrokePattern::apply(GraphicsContext& context) const
 860{
 861 context.applyStrokePattern();
 862}
 863
 864void ApplyFillPattern::apply(GraphicsContext& context) const
 865{
 866 context.applyFillPattern();
 867}
 868
 869void ApplyDeviceScaleFactor::apply(GraphicsContext& context) const
 870{
 871 context.applyDeviceScaleFactor(m_scaleFactor);
 872}
 873
 874static TextStream& operator<<(TextStream& ts, const ApplyDeviceScaleFactor& item)
 875{
 876 ts.dumpProperty("scale-factor", item.scaleFactor());
 877 return ts;
 878}
 879
 880static TextStream& operator<<(TextStream& ts, const ItemType& type)
 881{
 882 switch (type) {
 883 case ItemType::Save: ts << "save"; break;
 884 case ItemType::Restore: ts << "restore"; break;
 885 case ItemType::Translate: ts << "translate"; break;
 886 case ItemType::Rotate: ts << "rotate"; break;
 887 case ItemType::Scale: ts << "scale"; break;
 888 case ItemType::ConcatenateCTM: ts << "concatentate-ctm"; break;
 889 case ItemType::SetState: ts << "set-state"; break;
 890 case ItemType::SetLineCap: ts << "set-line-cap"; break;
 891 case ItemType::SetLineDash: ts << "set-line-dash"; break;
 892 case ItemType::SetLineJoin: ts << "set-line-join"; break;
 893 case ItemType::SetMiterLimit: ts << "set-miter-limit"; break;
 894 case ItemType::Clip: ts << "clip"; break;
 895 case ItemType::ClipOut: ts << "clip-out"; break;
 896 case ItemType::ClipOutToPath: ts << "clip-out-to-path"; break;
 897 case ItemType::ClipPath: ts << "clip-path"; break;
 898 case ItemType::ClipConvexPolygon: ts << "clip-convex-polygon"; break;
 899 case ItemType::DrawGlyphs: ts << "draw-glyphs"; break;
 900 case ItemType::DrawImage: ts << "draw-image"; break;
 901 case ItemType::DrawTiledImage: ts << "draw-tiled-image"; break;
 902 case ItemType::DrawTiledScaledImage: ts << "draw-tiled-scaled-image"; break;
 903 case ItemType::DrawNativeImage: ts << "draw-native-image"; break;
 904 case ItemType::DrawPattern: ts << "draw-pattern"; break;
 905 case ItemType::DrawRect: ts << "draw-rect"; break;
 906 case ItemType::DrawLine: ts << "draw-line"; break;
 907 case ItemType::DrawLinesForText: ts << "draw-lines-for-text"; break;
 908 case ItemType::DrawLineForDocumentMarker: ts << "draw-lines-for-document-marker"; break;
 909 case ItemType::DrawEllipse: ts << "draw-ellipse"; break;
 910 case ItemType::DrawConvexPolygon: ts << "draw-convex-polgon"; break;
 911 case ItemType::DrawPath: ts << "draw-path"; break;
 912 case ItemType::DrawFocusRingPath: ts << "draw-focus-ring-path"; break;
 913 case ItemType::DrawFocusRingRects: ts << "draw-focus-ring-rects"; break;
 914 case ItemType::FillRect: ts << "fill-rect"; break;
 915 case ItemType::FillRectWithColor: ts << "fill-rect-with-color"; break;
 916 case ItemType::FillRectWithGradient: ts << "fill-rect-with-gradient"; break;
 917 case ItemType::FillCompositedRect: ts << "fill-composited-rect"; break;
 918 case ItemType::FillRoundedRect: ts << "fill-rounded-rect"; break;
 919 case ItemType::FillRectWithRoundedHole: ts << "fill-rect-with-rounded-hole"; break;
 920 case ItemType::FillPath: ts << "fill-path"; break;
 921 case ItemType::FillEllipse: ts << "fill-ellipse"; break;
 922 case ItemType::StrokeRect: ts << "stroke-rect"; break;
 923 case ItemType::StrokePath: ts << "stroke-path"; break;
 924 case ItemType::StrokeEllipse: ts << "stroke-ellipse"; break;
 925 case ItemType::ClearRect: ts << "clear-rect"; break;
 926 case ItemType::BeginTransparencyLayer: ts << "begin-transparency-layer"; break;
 927 case ItemType::EndTransparencyLayer: ts << "end-transparency-layer"; break;
 928 case ItemType::ApplyStrokePattern: ts << "apply-stroke-pattern"; break;
 929 case ItemType::ApplyFillPattern: ts << "apply-fill-pattern"; break;
 930 case ItemType::ApplyDeviceScaleFactor: ts << "apply-device-scale-factor"; break;
 931 case ItemType::ClearShadow: ts << "clear-shadow"; break;
 932 }
 933 return ts;
 934}
 935
 936TextStream& operator<<(TextStream& ts, const Item& item)
 937{
 938 TextStream::GroupScope group(ts);
 939 ts << item.type();
 940
 941 // FIXME: Make a macro which takes a macro for all these enumeration switches
 942 switch (item.type()) {
 943 case ItemType::Save:
 944 ts << downcast<Save>(item);
 945 break;
 946 case ItemType::Translate:
 947 ts << downcast<Translate>(item);
 948 break;
 949 case ItemType::Rotate:
 950 ts << downcast<Rotate>(item);
 951 break;
 952 case ItemType::Scale:
 953 ts << downcast<Scale>(item);
 954 break;
 955 case ItemType::ConcatenateCTM:
 956 ts << downcast<ConcatenateCTM>(item);
 957 break;
 958 case ItemType::SetState:
 959 ts << downcast<SetState>(item);
 960 break;
 961 case ItemType::SetLineCap:
 962 ts << downcast<SetLineCap>(item);
 963 break;
 964 case ItemType::SetLineDash:
 965 ts << downcast<SetLineDash>(item);
 966 break;
 967 case ItemType::SetLineJoin:
 968 ts << downcast<SetLineJoin>(item);
 969 break;
 970 case ItemType::SetMiterLimit:
 971 ts << downcast<SetMiterLimit>(item);
 972 break;
 973 case ItemType::Clip:
 974 ts << downcast<Clip>(item);
 975 break;
 976 case ItemType::ClipOut:
 977 ts << downcast<ClipOut>(item);
 978 break;
 979 case ItemType::ClipOutToPath:
 980 ts << downcast<ClipOutToPath>(item);
 981 break;
 982 case ItemType::ClipPath:
 983 ts << downcast<ClipPath>(item);
 984 break;
 985 case ItemType::ClipConvexPolygon:
 986 ts << downcast<ClipConvexPolygon>(item);
 987 break;
 988 case ItemType::DrawGlyphs:
 989 ts << downcast<DrawGlyphs>(item);
 990 break;
 991 case ItemType::DrawImage:
 992 ts << downcast<DrawImage>(item);
 993 break;
 994 case ItemType::DrawTiledImage:
 995 ts << downcast<DrawTiledImage>(item);
 996 break;
 997 case ItemType::DrawTiledScaledImage:
 998 ts << downcast<DrawTiledScaledImage>(item);
 999 break;
 1000 case ItemType::DrawNativeImage:
 1001 ts << downcast<DrawNativeImage>(item);
 1002 break;
 1003 case ItemType::DrawPattern:
 1004 ts << downcast<DrawPattern>(item);
 1005 break;
 1006 case ItemType::DrawRect:
 1007 ts << downcast<DrawRect>(item);
 1008 break;
 1009 case ItemType::DrawLine:
 1010 ts << downcast<DrawLine>(item);
 1011 break;
 1012 case ItemType::DrawLinesForText:
 1013 ts << downcast<DrawLinesForText>(item);
 1014 break;
 1015 case ItemType::DrawLineForDocumentMarker:
 1016 ts << downcast<DrawLineForDocumentMarker>(item);
 1017 break;
 1018 case ItemType::DrawEllipse:
 1019 ts << downcast<DrawEllipse>(item);
 1020 break;
 1021 case ItemType::DrawConvexPolygon:
 1022 ts << downcast<DrawConvexPolygon>(item);
 1023 break;
 1024 case ItemType::DrawPath:
 1025 ts << downcast<DrawPath>(item);
 1026 break;
 1027 case ItemType::DrawFocusRingPath:
 1028 ts << downcast<DrawFocusRingPath>(item);
 1029 break;
 1030 case ItemType::DrawFocusRingRects:
 1031 ts << downcast<DrawFocusRingRects>(item);
 1032 break;
 1033 case ItemType::FillRect:
 1034 ts << downcast<FillRect>(item);
 1035 break;
 1036 case ItemType::FillRectWithColor:
 1037 ts << downcast<FillRectWithColor>(item);
 1038 break;
 1039 case ItemType::FillRectWithGradient:
 1040 ts << downcast<FillRectWithGradient>(item);
 1041 break;
 1042 case ItemType::FillCompositedRect:
 1043 ts << downcast<FillCompositedRect>(item);
 1044 break;
 1045 case ItemType::FillRoundedRect:
 1046 ts << downcast<FillRoundedRect>(item);
 1047 break;
 1048 case ItemType::FillRectWithRoundedHole:
 1049 ts << downcast<FillRectWithRoundedHole>(item);
 1050 break;
 1051 case ItemType::FillPath:
 1052 ts << downcast<FillPath>(item);
 1053 break;
 1054 case ItemType::FillEllipse:
 1055 ts << downcast<FillEllipse>(item);
 1056 break;
 1057 case ItemType::StrokeRect:
 1058 ts << downcast<StrokeRect>(item);
 1059 break;
 1060 case ItemType::StrokePath:
 1061 ts << downcast<StrokePath>(item);
 1062 break;
 1063 case ItemType::StrokeEllipse:
 1064 ts << downcast<StrokeEllipse>(item);
 1065 break;
 1066 case ItemType::ClearRect:
 1067 ts << downcast<ClearRect>(item);
 1068 break;
 1069 case ItemType::BeginTransparencyLayer:
 1070 ts << downcast<BeginTransparencyLayer>(item);
 1071 break;
 1072 case ItemType::ApplyDeviceScaleFactor:
 1073 ts << downcast<ApplyDeviceScaleFactor>(item);
 1074 break;
 1075
 1076 // Items with no additional data.
 1077 case ItemType::Restore:
 1078 case ItemType::EndTransparencyLayer:
 1079 case ItemType::ApplyStrokePattern:
 1080 case ItemType::ApplyFillPattern:
 1081 case ItemType::ClearShadow:
 1082 break;
 1083 }
 1084 return ts;
 1085}
 1086
 1087}
 1088}

Source/WebCore/platform/graphics/displaylists/DisplayListItems.h

 1/*
 2 * Copyright (C) 2015 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#ifndef DisplayListItems_h
 27#define DisplayListItems_h
 28
 29#include "FloatPoint.h"
 30#include "FloatRect.h"
 31#include "FloatRoundedRect.h"
 32#include "Font.h"
 33#include "GlyphBuffer.h"
 34#include "GraphicsContext.h"
 35#include "Image.h"
 36#include <wtf/RefCounted.h>
 37#include <wtf/TypeCasts.h>
 38
 39#if USE(CG)
 40#include "GraphicsContextPlatformPrivateCG.h"
 41#endif
 42
 43namespace WebCore {
 44
 45class TextStream;
 46struct ImagePaintingOptions;
 47
 48namespace DisplayList {
 49
 50enum class ItemType {
 51 Save,
 52 Restore,
 53 Translate,
 54 Rotate,
 55 Scale,
 56 ConcatenateCTM,
 57 SetState,
 58 SetLineCap,
 59 SetLineDash,
 60 SetLineJoin,
 61 SetMiterLimit,
 62 ClearShadow,
 63 Clip,
 64 ClipOut,
 65 ClipOutToPath,
 66 ClipPath,
 67 ClipConvexPolygon,
 68 DrawGlyphs,
 69 DrawImage,
 70 DrawTiledImage,
 71 DrawTiledScaledImage,
 72 DrawNativeImage,
 73 DrawPattern,
 74 DrawRect,
 75 DrawLine,
 76 DrawLinesForText,
 77 DrawLineForDocumentMarker,
 78 DrawEllipse,
 79 DrawConvexPolygon,
 80 DrawPath,
 81 DrawFocusRingPath,
 82 DrawFocusRingRects,
 83 FillRect,
 84 FillRectWithColor,
 85 FillRectWithGradient,
 86 FillCompositedRect,
 87 FillRoundedRect,
 88 FillRectWithRoundedHole,
 89 FillPath,
 90 FillEllipse,
 91 StrokeRect,
 92 StrokePath,
 93 StrokeEllipse,
 94 ClearRect,
 95 BeginTransparencyLayer,
 96 EndTransparencyLayer,
 97 ApplyStrokePattern, // FIXME: should not be a recorded item.
 98 ApplyFillPattern, // FIXME: should not be a recorded item.
 99 ApplyDeviceScaleFactor,
 100};
 101
 102class Item : public RefCounted<Item> {
 103public:
 104 Item() = delete;
 105
 106 Item(ItemType type)
 107 : m_type(type)
 108 {
 109 }
 110
 111 virtual ~Item() { }
 112
 113 ItemType type() const
 114 {
 115 return m_type;
 116 }
 117
 118 virtual void apply(GraphicsContext&) const = 0;
 119
 120 static constexpr bool isDisplayListItem = true;
 121
 122 virtual bool isDrawingItem() const { return false; }
 123
 124 // A state item is one preserved by Save/Restore.
 125 bool isStateItem() const
 126 {
 127 return isStateItemType(m_type);
 128 }
 129
 130 static bool isStateItemType(ItemType itemType)
 131 {
 132 switch (itemType) {
 133 case ItemType:: Translate:
 134 case ItemType:: Rotate:
 135 case ItemType:: Scale:
 136 case ItemType:: ConcatenateCTM:
 137 case ItemType:: SetState:
 138 case ItemType:: SetLineCap:
 139 case ItemType:: SetLineDash:
 140 case ItemType:: SetLineJoin:
 141 case ItemType:: SetMiterLimit:
 142 case ItemType:: ClearShadow:
 143 return true;
 144 default:
 145 return false;
 146 }
 147 return false;
 148 }
 149
 150#if !defined(NDEBUG) || !LOG_DISABLED
 151 WTF::CString description() const;
 152#endif
 153
 154private:
 155 ItemType m_type;
 156};
 157
 158class DrawingItem : public Item {
 159public:
 160 DrawingItem(ItemType type)
 161 : Item(type)
 162 {
 163 }
 164
 165 void setExtent(const FloatRect& r) { m_extent = r; }
 166 const FloatRect& extent() const { return m_extent.value(); }
 167
 168 bool extentKnown() const { return static_cast<bool>(m_extent); }
 169
 170 // Return bounds of this drawing operation in local coordinates.
 171 // Does not include effets of transform, shadow etc in the state.
 172 virtual Optional<FloatRect> localBounds(const GraphicsContext&) const { return Nullopt; }
 173
 174private:
 175 virtual bool isDrawingItem() const { return true; }
 176
 177 Optional<FloatRect> m_extent; // In base coordinates, taking shadows and transforms into account.
 178};
 179
 180class Save : public Item {
 181public:
 182 static Ref<Save> create()
 183 {
 184 return adoptRef(*new Save);
 185 }
 186
 187 // Index in the display list of the corresponding Restore item. 0 if unmatched.
 188 size_t restoreIndex() const { return m_restoreIndex; }
 189 void setRestoreIndex(size_t index) { m_restoreIndex = index; }
 190
 191private:
 192 Save()
 193 : Item(ItemType::Save)
 194 {
 195 }
 196
 197 virtual void apply(GraphicsContext&) const override;
 198
 199 size_t m_restoreIndex { 0 };
 200};
 201
 202class Restore : public Item {
 203public:
 204 static Ref<Restore> create()
 205 {
 206 return adoptRef(*new Restore);
 207 }
 208
 209private:
 210 Restore()
 211 : Item(ItemType::Restore)
 212 {
 213 }
 214
 215 virtual void apply(GraphicsContext&) const override;
 216};
 217
 218class Translate : public Item {
 219public:
 220 static Ref<Translate> create(float x, float y)
 221 {
 222 return adoptRef(*new Translate(x, y));
 223 }
 224
 225 float x() const { return m_x; }
 226 float y() const { return m_y; }
 227
 228private:
 229 Translate(float x, float y)
 230 : Item(ItemType::Translate)
 231 , m_x(x)
 232 , m_y(y)
 233 {
 234 }
 235
 236 virtual void apply(GraphicsContext&) const override;
 237
 238 float m_x;
 239 float m_y;
 240};
 241
 242class Rotate : public Item {
 243public:
 244 static Ref<Rotate> create(float angleInRadians)
 245 {
 246 return adoptRef(*new Rotate(angleInRadians));
 247 }
 248
 249 float angle() const { return m_angle; }
 250
 251private:
 252 Rotate(float angle)
 253 : Item(ItemType::Rotate)
 254 , m_angle(angle)
 255 {
 256 }
 257
 258 virtual void apply(GraphicsContext&) const override;
 259
 260 float m_angle; // In radians.
 261};
 262
 263class Scale : public Item {
 264public:
 265 static Ref<Scale> create(const FloatSize& size)
 266 {
 267 return adoptRef(*new Scale(size));
 268 }
 269
 270 const FloatSize& amount() const { return m_size; }
 271
 272private:
 273 Scale(const FloatSize& size)
 274 : Item(ItemType::Scale)
 275 , m_size(size)
 276 {
 277 }
 278
 279 virtual void apply(GraphicsContext&) const override;
 280
 281 FloatSize m_size;
 282};
 283
 284class ConcatenateCTM : public Item {
 285public:
 286 static Ref<ConcatenateCTM> create(const AffineTransform& matrix)
 287 {
 288 return adoptRef(*new ConcatenateCTM(matrix));
 289 }
 290
 291 const AffineTransform& transform() const { return m_transform; }
 292
 293private:
 294 ConcatenateCTM(const AffineTransform&);
 295
 296 virtual void apply(GraphicsContext&) const override;
 297
 298 AffineTransform m_transform;
 299};
 300
 301class SetState : public Item {
 302public:
 303 static Ref<SetState> create(const GraphicsContextState& state, GraphicsContextState::StateChangeFlags flags)
 304 {
 305 return adoptRef(*new SetState(state, flags));
 306 }
 307
 308 const GraphicsContextStateChange& state() const { return m_state; }
 309
 310 void accumulate(const GraphicsContextState&, GraphicsContextState::StateChangeFlags);
 311
 312 void accumulate(GraphicsContextState&) const;
 313
 314 static void applyState(GraphicsContext&, const GraphicsContextState&, GraphicsContextState::StateChangeFlags);
 315
 316 static void dumpStateChanges(TextStream&, const GraphicsContextState&, GraphicsContextState::StateChangeFlags);
 317private:
 318 SetState(const GraphicsContextState& state, GraphicsContextState::StateChangeFlags flags)
 319 : Item(ItemType::SetState)
 320 , m_state(state, flags)
 321 {
 322 }
 323
 324 virtual void apply(GraphicsContext&) const override;
 325
 326 GraphicsContextStateChange m_state;
 327};
 328
 329class SetLineCap : public Item {
 330public:
 331 static Ref<SetLineCap> create(LineCap lineCap)
 332 {
 333 return adoptRef(*new SetLineCap(lineCap));
 334 }
 335
 336 LineCap lineCap() const { return m_lineCap; }
 337
 338private:
 339 SetLineCap(LineCap lineCap)
 340 : Item(ItemType::SetLineCap)
 341 , m_lineCap(lineCap)
 342 {
 343 }
 344
 345 virtual void apply(GraphicsContext&) const override;
 346
 347 LineCap m_lineCap;
 348};
 349
 350class SetLineDash : public Item {
 351public:
 352 static Ref<SetLineDash> create(const DashArray& dashArray, float dashOffset)
 353 {
 354 return adoptRef(*new SetLineDash(dashArray, dashOffset));
 355 }
 356
 357 const DashArray& dashArray() const { return m_dashArray; }
 358 float dashOffset() const { return m_dashOffset; }
 359
 360private:
 361 SetLineDash(const DashArray& dashArray, float dashOffset)
 362 : Item(ItemType::SetLineDash)
 363 , m_dashArray(dashArray)
 364 , m_dashOffset(dashOffset)
 365 {
 366 }
 367
 368 virtual void apply(GraphicsContext&) const override;
 369
 370 DashArray m_dashArray;
 371 float m_dashOffset;
 372};
 373
 374class SetLineJoin : public Item {
 375public:
 376 static Ref<SetLineJoin> create(LineJoin lineJoin)
 377 {
 378 return adoptRef(*new SetLineJoin(lineJoin));
 379 }
 380
 381 LineJoin lineJoin() const { return m_lineJoin; }
 382
 383private:
 384 SetLineJoin(LineJoin lineJoin)
 385 : Item(ItemType::SetLineJoin)
 386 , m_lineJoin(lineJoin)
 387 {
 388 }
 389
 390 virtual void apply(GraphicsContext&) const override;
 391
 392 LineJoin m_lineJoin;
 393};
 394
 395class SetMiterLimit : public Item {
 396public:
 397 static Ref<SetMiterLimit> create(float limit)
 398 {
 399 return adoptRef(*new SetMiterLimit(limit));
 400 }
 401
 402 float miterLimit() const { return m_miterLimit; }
 403
 404private:
 405 SetMiterLimit(float miterLimit)
 406 : Item(ItemType::SetMiterLimit)
 407 , m_miterLimit(miterLimit)
 408 {
 409 }
 410
 411 virtual void apply(GraphicsContext&) const override;
 412
 413 float m_miterLimit;
 414};
 415
 416class ClearShadow : public Item {
 417public:
 418 static Ref<ClearShadow> create()
 419 {
 420 return adoptRef(*new ClearShadow);
 421 }
 422
 423private:
 424 ClearShadow()
 425 : Item(ItemType::ClearShadow)
 426 {
 427 }
 428
 429 virtual void apply(GraphicsContext&) const override;
 430};
 431
 432// FIXME: treat as DrawingItem?
 433class Clip : public Item {
 434public:
 435 static Ref<Clip> create(const FloatRect& rect)
 436 {
 437 return adoptRef(*new Clip(rect));
 438 }
 439
 440 FloatRect rect() const { return m_rect; }
 441
 442private:
 443 Clip(const FloatRect& rect)
 444 : Item(ItemType::Clip)
 445 , m_rect(rect)
 446 {
 447 }
 448
 449 virtual void apply(GraphicsContext&) const override;
 450
 451 FloatRect m_rect;
 452};
 453
 454class ClipOut : public Item {
 455public:
 456 static Ref<ClipOut> create(const FloatRect& rect)
 457 {
 458 return adoptRef(*new ClipOut(rect));
 459 }
 460
 461 FloatRect rect() const { return m_rect; }
 462
 463private:
 464 ClipOut(const FloatRect& rect)
 465 : Item(ItemType::ClipOut)
 466 , m_rect(rect)
 467 {
 468 }
 469
 470 virtual void apply(GraphicsContext&) const override;
 471
 472 FloatRect m_rect;
 473};
 474
 475class ClipOutToPath : public Item {
 476public:
 477 static Ref<ClipOutToPath> create(const Path& path)
 478 {
 479 return adoptRef(*new ClipOutToPath(path));
 480 }
 481
 482 const Path& path() const { return m_path; }
 483
 484private:
 485 ClipOutToPath(const Path& path)
 486 : Item(ItemType::ClipOutToPath)
 487 , m_path(path)
 488 {
 489 }
 490
 491 virtual void apply(GraphicsContext&) const override;
 492
 493 Path m_path;
 494};
 495
 496class ClipPath : public Item {
 497public:
 498 static Ref<ClipPath> create(const Path& path, WindRule windRule)
 499 {
 500 return adoptRef(*new ClipPath(path, windRule));
 501 }
 502
 503 const Path& path() const { return m_path; }
 504 WindRule windRule() const { return m_windRule; }
 505
 506private:
 507 ClipPath(const Path& path, WindRule windRule)
 508 : Item(ItemType::ClipPath)
 509 , m_path(path)
 510 , m_windRule(windRule)
 511 {
 512 }
 513
 514 virtual void apply(GraphicsContext&) const override;
 515
 516 Path m_path;
 517 WindRule m_windRule;
 518};
 519
 520class ClipConvexPolygon : public Item {
 521public:
 522 static Ref<ClipConvexPolygon> create(size_t numberOfPoints, const FloatPoint* points, bool antialiased)
 523 {
 524 return adoptRef(*new ClipConvexPolygon(numberOfPoints, points, antialiased));
 525 }
 526
 527 const Vector<FloatPoint>& points() const { return m_points; }
 528 bool antialias() const { return m_antialias; }
 529
 530private:
 531 ClipConvexPolygon(size_t numberOfPoints, const FloatPoint*, bool antialiased);
 532
 533 virtual void apply(GraphicsContext&) const override;
 534
 535 Vector<FloatPoint> m_points;
 536 bool m_antialias;
 537};
 538
 539class DrawGlyphs : public DrawingItem {
 540public:
 541 static Ref<DrawGlyphs> create(const Font& font, const GlyphBufferGlyph* glyphs, const GlyphBufferAdvance* advances, unsigned count, const FloatPoint& blockLocation, const FloatSize& localAnchor, FontSmoothingMode smoothingMode)
 542 {
 543 return adoptRef(*new DrawGlyphs(font, glyphs, advances, count, blockLocation, localAnchor, smoothingMode));
 544 }
 545
 546 const FloatPoint& blockLocation() const { return m_blockLocation; }
 547 void setBlockLocation(const FloatPoint& blockLocation) { m_blockLocation = blockLocation; }
 548
 549 const FloatSize& localAnchor() const { return m_localAnchor; }
 550
 551 FloatPoint anchorPoint() const { return m_blockLocation + m_localAnchor; }
 552
 553 const Vector<GlyphBufferGlyph, 128>& glyphs() const { return m_glyphs; }
 554
 555private:
 556 DrawGlyphs(const Font&, const GlyphBufferGlyph*, const GlyphBufferAdvance*, unsigned count, const FloatPoint& blockLocation, const FloatSize& localAnchor, FontSmoothingMode);
 557
 558 void computeBounds();
 559
 560 virtual void apply(GraphicsContext&) const override;
 561
 562 virtual Optional<FloatRect> localBounds(const GraphicsContext&) const override;
 563
 564 GlyphBuffer generateGlyphBuffer() const;
 565
 566 Ref<Font> m_font;
 567 Vector<GlyphBufferGlyph, 128> m_glyphs;
 568 Vector<GlyphBufferAdvance, 128> m_advances;
 569 FloatRect m_bounds;
 570 FloatPoint m_blockLocation;
 571 FloatSize m_localAnchor;
 572 FontSmoothingMode m_smoothingMode;
 573};
 574
 575class DrawImage : public DrawingItem {
 576public:
 577 static Ref<DrawImage> create(Image& image, const FloatRect& destination, const FloatRect& source, const ImagePaintingOptions& imagePaintingOptions)
 578 {
 579 return adoptRef(*new DrawImage(image, destination, source, imagePaintingOptions));
 580 }
 581
 582 const Image& image() const { return m_image.get(); }
 583 FloatRect source() const { return m_source; }
 584 FloatRect destination() const { return m_destination; }
 585
 586private:
 587 DrawImage(Image&, const FloatRect& destination, const FloatRect& source, const ImagePaintingOptions&);
 588
 589 virtual void apply(GraphicsContext&) const override;
 590
 591 virtual Optional<FloatRect> localBounds(const GraphicsContext&) const override { return m_destination; }
 592
 593 mutable Ref<Image> m_image; // FIXME: Drawing images can cause their animations to progress. This shouldn't have to be mutable.
 594 FloatRect m_destination;
 595 FloatRect m_source;
 596 ImagePaintingOptions m_imagePaintingOptions;
 597};
 598
 599class DrawTiledImage : public DrawingItem {
 600public:
 601 static Ref<DrawTiledImage> create(Image& image, const FloatRect& destination, const FloatPoint& source, const FloatSize& tileSize, const FloatSize& spacing, const ImagePaintingOptions& imagePaintingOptions)
 602 {
 603 return adoptRef(*new DrawTiledImage(image, destination, source, tileSize, spacing, imagePaintingOptions));
 604 }
 605
 606 const Image& image() const { return m_image.get(); }
 607 FloatPoint source() const { return m_source; }
 608 FloatRect destination() const { return m_destination; }
 609
 610 FloatSize tileSize() const { return m_tileSize; }
 611 FloatSize spacing() const { return m_spacing; }
 612
 613private:
 614 DrawTiledImage(Image&, const FloatRect& destination, const FloatPoint& source, const FloatSize& tileSize, const FloatSize& spacing, const ImagePaintingOptions&);
 615
 616 virtual void apply(GraphicsContext&) const override;
 617
 618 virtual Optional<FloatRect> localBounds(const GraphicsContext&) const override { return m_destination; }
 619
 620 mutable Ref<Image> m_image; // FIXME: Drawing images can cause their animations to progress. This shouldn't have to be mutable.
 621 FloatRect m_destination;
 622 FloatPoint m_source;
 623 FloatSize m_tileSize;
 624 FloatSize m_spacing;
 625 ImagePaintingOptions m_imagePaintingOptions;
 626};
 627
 628class DrawTiledScaledImage : public DrawingItem {
 629public:
 630 static Ref<DrawTiledScaledImage> create(Image& image, const FloatRect& destination, const FloatRect& source, const FloatSize& tileScaleFactor, Image::TileRule hRule, Image::TileRule vRule, const ImagePaintingOptions& imagePaintingOptions)
 631 {
 632 return adoptRef(*new DrawTiledScaledImage(image, destination, source, tileScaleFactor, hRule, vRule, imagePaintingOptions));
 633 }
 634
 635 const Image& image() const { return m_image.get(); }
 636 FloatRect source() const { return m_source; }
 637 FloatRect destination() const { return m_destination; }
 638
 639private:
 640 DrawTiledScaledImage(Image&, const FloatRect& destination, const FloatRect& source, const FloatSize& tileScaleFactor, Image::TileRule hRule, Image::TileRule vRule, const ImagePaintingOptions&);
 641
 642 virtual void apply(GraphicsContext&) const override;
 643
 644 virtual Optional<FloatRect> localBounds(const GraphicsContext&) const override { return m_destination; }
 645
 646 mutable Ref<Image> m_image; // FIXME: Drawing images can cause their animations to progress. This shouldn't have to be mutable.
 647 FloatRect m_destination;
 648 FloatRect m_source;
 649 FloatSize m_tileScaleFactor;
 650 Image::TileRule m_hRule;
 651 Image::TileRule m_vRule;
 652 ImagePaintingOptions m_imagePaintingOptions;
 653};
 654
 655class DrawNativeImage : public DrawingItem {
 656public:
 657 static Ref<DrawNativeImage> create(PassNativeImagePtr imagePtr, const FloatSize& imageSize, const FloatRect& destRect, const FloatRect& srcRect, CompositeOperator op, BlendMode blendMode, ImageOrientation orientation)
 658 {
 659 return adoptRef(*new DrawNativeImage(imagePtr, imageSize, destRect, srcRect, op, blendMode, orientation));
 660 }
 661
 662 FloatRect source() const { return m_srcRect; }
 663 FloatRect destination() const { return m_destination; }
 664
 665private:
 666 DrawNativeImage(PassNativeImagePtr, const FloatSize& selfSize, const FloatRect& destRect, const FloatRect& srcRect, CompositeOperator, BlendMode, ImageOrientation);
 667
 668 virtual void apply(GraphicsContext&) const override;
 669
 670 virtual Optional<FloatRect> localBounds(const GraphicsContext&) const override { return m_destination; }
 671
 672#if USE(CG)
 673 RetainPtr<CGImageRef> m_imagePtr;
 674#endif
 675 FloatSize m_imageSize;
 676 FloatRect m_destination;
 677 FloatRect m_srcRect;
 678 CompositeOperator m_op;
 679 BlendMode m_blendMode;
 680 ImageOrientation m_orientation;
 681};
 682
 683class DrawPattern : public DrawingItem {
 684public:
 685 static Ref<DrawPattern> create(Image& image, const FloatRect& tileRect, const AffineTransform& patternTransform, const FloatPoint& phase, const FloatSize& spacing, CompositeOperator op, const FloatRect& destRect, BlendMode blendMode)
 686 {
 687 return adoptRef(*new DrawPattern(image, tileRect, patternTransform, phase, spacing, op, destRect, blendMode));
 688 }
 689
 690 const Image& image() const { return m_image.get(); }
 691 const AffineTransform& patternTransform() const { return m_patternTransform; }
 692 FloatRect tileRect() const { return m_tileRect; }
 693 FloatRect destRect() const { return m_destination; }
 694 FloatPoint phase() const { return m_phase; }
 695 FloatSize spacing() const { return m_spacing; }
 696
 697private:
 698 DrawPattern(Image&, const FloatRect& srcRect, const AffineTransform&, const FloatPoint& phase, const FloatSize& spacing, CompositeOperator, const FloatRect& destRect, BlendMode = BlendModeNormal);
 699
 700 virtual void apply(GraphicsContext&) const override;
 701
 702 virtual Optional<FloatRect> localBounds(const GraphicsContext&) const override { return m_destination; }
 703
 704 mutable Ref<Image> m_image; // FIXME: Drawing images can cause their animations to progress. This shouldn't have to be mutable.
 705 AffineTransform m_patternTransform;
 706 FloatRect m_tileRect;
 707 FloatRect m_destination;
 708 FloatPoint m_phase;
 709 FloatSize m_spacing;
 710 CompositeOperator m_op;
 711 BlendMode m_blendMode;
 712};
 713
 714// Is DrawingItem because the size of the transparency layer is implicitly the clip bounds.
 715class BeginTransparencyLayer : public DrawingItem {
 716public:
 717 static Ref<BeginTransparencyLayer> create(float opacity)
 718 {
 719 return adoptRef(*new BeginTransparencyLayer(opacity));
 720 }
 721
 722 float opacity() const { return m_opacity; }
 723
 724private:
 725 BeginTransparencyLayer(float opacity)
 726 : DrawingItem(ItemType::BeginTransparencyLayer)
 727 , m_opacity(opacity)
 728 {
 729 }
 730
 731 virtual void apply(GraphicsContext&) const override;
 732
 733 float m_opacity;
 734};
 735
 736class EndTransparencyLayer : public DrawingItem {
 737public:
 738 static Ref<EndTransparencyLayer> create()
 739 {
 740 return adoptRef(*new EndTransparencyLayer);
 741 }
 742
 743private:
 744 EndTransparencyLayer()
 745 : DrawingItem(ItemType::EndTransparencyLayer)
 746 {
 747 }
 748
 749 virtual void apply(GraphicsContext&) const override;
 750};
 751
 752class DrawRect : public DrawingItem {
 753public:
 754 static Ref<DrawRect> create(const FloatRect& rect, float borderThickness)
 755 {
 756 return adoptRef(*new DrawRect(rect, borderThickness));
 757 }
 758
 759 FloatRect rect() const { return m_rect; }
 760 float borderThickness() const { return m_borderThickness; }
 761
 762private:
 763 DrawRect(const FloatRect& rect, float borderThickness)
 764 : DrawingItem(ItemType::DrawRect)
 765 , m_rect(rect)
 766 , m_borderThickness(borderThickness)
 767 {
 768 }
 769
 770 virtual void apply(GraphicsContext&) const override;
 771 virtual Optional<FloatRect> localBounds(const GraphicsContext&) const override { return m_rect; }
 772
 773 FloatRect m_rect;
 774 float m_borderThickness;
 775};
 776
 777class DrawLine : public DrawingItem {
 778public:
 779 static Ref<DrawLine> create(const FloatPoint& point1, const FloatPoint& point2)
 780 {
 781 return adoptRef(*new DrawLine(point1, point2));
 782 }
 783
 784 FloatPoint point1() const { return m_point1; }
 785 FloatPoint point2() const { return m_point2; }
 786
 787private:
 788 DrawLine(const FloatPoint& point1, const FloatPoint& point2)
 789 : DrawingItem(ItemType::DrawLine)
 790 , m_point1(point1)
 791 , m_point2(point2)
 792 {
 793 }
 794
 795 virtual void apply(GraphicsContext&) const override;
 796 virtual Optional<FloatRect> localBounds(const GraphicsContext&) const override;
 797
 798 FloatPoint m_point1;
 799 FloatPoint m_point2;
 800};
 801
 802class DrawLinesForText : public DrawingItem {
 803public:
 804 static Ref<DrawLinesForText> create(const FloatPoint& blockLocation, const FloatSize& localAnchor, const DashArray& widths, bool printing, bool doubleLines, float strokeWidth)
 805 {
 806 return adoptRef(*new DrawLinesForText(blockLocation, localAnchor, widths, printing, doubleLines, strokeWidth));
 807 }
 808
 809 void setBlockLocation(const FloatPoint& blockLocation) { m_blockLocation = blockLocation; }
 810 const FloatPoint& blockLocation() const { return m_blockLocation; }
 811 const FloatSize& localAnchor() const { return m_localAnchor; }
 812 FloatPoint point() const { return m_blockLocation + m_localAnchor; }
 813 const DashArray& widths() const { return m_widths; }
 814 bool isPrinting() const { return m_printing; }
 815 bool doubleLines() const { return m_doubleLines; }
 816
 817private:
 818 DrawLinesForText(const FloatPoint& blockLocation, const FloatSize& localAnchor, const DashArray& widths, bool printing, bool doubleLines, float strokeWidth)
 819 : DrawingItem(ItemType::DrawLinesForText)
 820 , m_blockLocation(blockLocation)
 821 , m_localAnchor(localAnchor)
 822 , m_widths(widths)
 823 , m_strokeWidth(strokeWidth)
 824 , m_printing(printing)
 825 , m_doubleLines(doubleLines)
 826 {
 827 }
 828
 829 virtual void apply(GraphicsContext&) const override;
 830
 831 virtual Optional<FloatRect> localBounds(const GraphicsContext&) const override;
 832
 833 FloatPoint m_blockLocation;
 834 FloatSize m_localAnchor;
 835 DashArray m_widths;
 836 float m_strokeWidth;
 837 bool m_printing;
 838 bool m_doubleLines;
 839};
 840
 841class DrawLineForDocumentMarker : public DrawingItem {
 842public:
 843 static Ref<DrawLineForDocumentMarker> create(const FloatPoint& point, float width, GraphicsContext::DocumentMarkerLineStyle style)
 844 {
 845 return adoptRef(*new DrawLineForDocumentMarker(point, width, style));
 846 }
 847
 848 FloatPoint point() const { return m_point; }
 849 float width() const { return m_width; }
 850
 851private:
 852 DrawLineForDocumentMarker(const FloatPoint& point, float width, GraphicsContext::DocumentMarkerLineStyle style)
 853 : DrawingItem(ItemType::DrawLineForDocumentMarker)
 854 , m_point(point)
 855 , m_width(width)
 856 , m_style(style)
 857 {
 858 }
 859
 860 virtual void apply(GraphicsContext&) const override;
 861
 862 virtual Optional<FloatRect> localBounds(const GraphicsContext&) const override;
 863
 864 FloatPoint m_point;
 865 float m_width;
 866 GraphicsContext::DocumentMarkerLineStyle m_style;
 867};
 868
 869class DrawEllipse : public DrawingItem {
 870public:
 871 static Ref<DrawEllipse> create(const FloatRect& rect)
 872 {
 873 return adoptRef(*new DrawEllipse(rect));
 874 }
 875
 876 FloatRect rect() const { return m_rect; }
 877
 878private:
 879 DrawEllipse(const FloatRect& rect)
 880 : DrawingItem(ItemType::DrawEllipse)
 881 , m_rect(rect)
 882 {
 883 }
 884
 885 virtual void apply(GraphicsContext&) const override;
 886 virtual Optional<FloatRect> localBounds(const GraphicsContext&) const override { return m_rect; }
 887
 888 FloatRect m_rect;
 889};
 890
 891class DrawConvexPolygon : public DrawingItem {
 892public:
 893 static Ref<DrawConvexPolygon> create(size_t numberOfPoints, const FloatPoint* points, bool antialiased)
 894 {
 895 return adoptRef(*new DrawConvexPolygon(numberOfPoints, points, antialiased));
 896 }
 897
 898 const Vector<FloatPoint>& points() const { return m_points; }
 899 bool antialiased() const { return m_antialiased; }
 900
 901private:
 902 DrawConvexPolygon(size_t numberOfPoints, const FloatPoint*, bool antialiased);
 903
 904 virtual void apply(GraphicsContext&) const override;
 905 virtual Optional<FloatRect> localBounds(const GraphicsContext&) const override;
 906
 907 Vector<FloatPoint> m_points;
 908 bool m_antialiased;
 909};
 910
 911class DrawPath : public DrawingItem {
 912public:
 913 static Ref<DrawPath> create(const Path& path)
 914 {
 915 return adoptRef(*new DrawPath(path));
 916 }
 917
 918 const Path& path() const { return m_path; }
 919
 920private:
 921 DrawPath(const Path& path)
 922 : DrawingItem(ItemType::DrawPath)
 923 , m_path(path)
 924 {
 925 }
 926
 927 virtual void apply(GraphicsContext&) const override;
 928
 929 virtual Optional<FloatRect> localBounds(const GraphicsContext&) const override { return m_path.fastBoundingRect(); }
 930
 931 Path m_path;
 932};
 933
 934class DrawFocusRingPath : public DrawingItem {
 935public:
 936 static Ref<DrawFocusRingPath> create(const Path& path, int width, int offset, const Color& color)
 937 {
 938 return adoptRef(*new DrawFocusRingPath(path, width, offset, color));
 939 }
 940
 941 const Path& path() const { return m_path; }
 942 int width() const { return m_width; }
 943 int offset() const { return m_offset; }
 944 Color color() const { return m_color; }
 945
 946private:
 947 DrawFocusRingPath(const Path& path, int width, int offset, const Color& color)
 948 : DrawingItem(ItemType::DrawFocusRingPath)
 949 , m_path(path)
 950 , m_width(width)
 951 , m_offset(offset)
 952 , m_color(color)
 953 {
 954 }
 955
 956 virtual void apply(GraphicsContext&) const override;
 957
 958 virtual Optional<FloatRect> localBounds(const GraphicsContext&) const override;
 959
 960 Path m_path;
 961 int m_width;
 962 int m_offset;
 963 Color m_color;
 964};
 965
 966class DrawFocusRingRects : public DrawingItem {
 967public:
 968 static Ref<DrawFocusRingRects> create(const Vector<IntRect>& rects, int width, int offset, const Color& color)
 969 {
 970 return adoptRef(*new DrawFocusRingRects(rects, width, offset, color));
 971 }
 972
 973 const Vector<IntRect> rects() const { return m_rects; }
 974 int width() const { return m_width; }
 975 int offset() const { return m_offset; }
 976 Color color() const { return m_color; }
 977
 978private:
 979 DrawFocusRingRects(const Vector<IntRect>& rects, int width, int offset, const Color& color)
 980 : DrawingItem(ItemType::DrawFocusRingRects)
 981 , m_rects(rects)
 982 , m_width(width)
 983 , m_offset(offset)
 984 , m_color(color)
 985 {
 986 }
 987
 988 virtual void apply(GraphicsContext&) const override;
 989
 990 virtual Optional<FloatRect> localBounds(const GraphicsContext&) const override;
 991
 992 Vector<IntRect> m_rects;
 993 int m_width;
 994 int m_offset;
 995 Color m_color;
 996};
 997
 998class FillRect : public DrawingItem {
 999public:
 1000 static Ref<FillRect> create(const FloatRect& rect)
 1001 {
 1002 return adoptRef(*new FillRect(rect));
 1003 }
 1004
 1005 FloatRect rect() const { return m_rect; }
 1006
 1007private:
 1008 FillRect(const FloatRect& rect)
 1009 : DrawingItem(ItemType::FillRect)
 1010 , m_rect(rect)
 1011 {
 1012 }
 1013
 1014 virtual void apply(GraphicsContext&) const override;
 1015 virtual Optional<FloatRect> localBounds(const GraphicsContext&) const override { return m_rect; }
 1016
 1017 FloatRect m_rect;
 1018};
 1019
 1020// FIXME: Make these inherit from FillRect proper.
 1021class FillRectWithColor : public DrawingItem {
 1022public:
 1023 static Ref<FillRectWithColor> create(const FloatRect& rect, const Color& color)
 1024 {
 1025 return adoptRef(*new FillRectWithColor(rect, color));
 1026 }
 1027
 1028 FloatRect rect() const { return m_rect; }
 1029 Color color() const { return m_color; }
 1030
 1031private:
 1032 FillRectWithColor(const FloatRect& rect, const Color& color)
 1033 : DrawingItem(ItemType::FillRectWithColor)
 1034 , m_rect(rect)
 1035 , m_color(color)
 1036 {
 1037 }
 1038
 1039 virtual void apply(GraphicsContext&) const override;
 1040 virtual Optional<FloatRect> localBounds(const GraphicsContext&) const override { return m_rect; }
 1041
 1042 FloatRect m_rect;
 1043 Color m_color;
 1044};
 1045
 1046class FillRectWithGradient : public DrawingItem {
 1047public:
 1048 static Ref<FillRectWithGradient> create(const FloatRect& rect, Gradient& gradient)
 1049 {
 1050 return adoptRef(*new FillRectWithGradient(rect, gradient));
 1051 }
 1052
 1053 FloatRect rect() const { return m_rect; }
 1054
 1055private:
 1056 FillRectWithGradient(const FloatRect& rect, Gradient& gradient)
 1057 : DrawingItem(ItemType::FillRectWithGradient)
 1058 , m_rect(rect)
 1059 , m_gradient(gradient)
 1060 {
 1061 }
 1062
 1063 virtual void apply(GraphicsContext&) const override;
 1064 virtual Optional<FloatRect> localBounds(const GraphicsContext&) const override { return m_rect; }
 1065
 1066 FloatRect m_rect;
 1067 mutable Ref<Gradient> m_gradient; // FIXME: Make this not mutable
 1068};
 1069
 1070class FillCompositedRect : public DrawingItem {
 1071public:
 1072 static Ref<FillCompositedRect> create(const FloatRect& rect, const Color& color, CompositeOperator op, BlendMode blendMode)
 1073 {
 1074 return adoptRef(*new FillCompositedRect(rect, color, op, blendMode));
 1075 }
 1076
 1077 FloatRect rect() const { return m_rect; }
 1078 Color color() const { return m_color; }
 1079 CompositeOperator compositeOperator() const { return m_op; }
 1080 BlendMode blendMode() const { return m_blendMode; }
 1081
 1082private:
 1083 FillCompositedRect(const FloatRect& rect, const Color& color, CompositeOperator op, BlendMode blendMode)
 1084 : DrawingItem(ItemType::FillCompositedRect)
 1085 , m_rect(rect)
 1086 , m_color(color)
 1087 , m_op(op)
 1088 , m_blendMode(blendMode)
 1089 {
 1090 }
 1091
 1092 virtual void apply(GraphicsContext&) const override;
 1093 virtual Optional<FloatRect> localBounds(const GraphicsContext&) const override { return m_rect; }
 1094
 1095 FloatRect m_rect;
 1096 Color m_color;
 1097 CompositeOperator m_op;
 1098 BlendMode m_blendMode;
 1099};
 1100
 1101class FillRoundedRect : public DrawingItem {
 1102public:
 1103 static Ref<FillRoundedRect> create(const FloatRoundedRect& rect, const Color& color, BlendMode blendMode)
 1104 {
 1105 return adoptRef(*new FillRoundedRect(rect, color, blendMode));
 1106 }
 1107
 1108 const FloatRoundedRect& roundedRect() const { return m_rect; }
 1109 Color color() const { return m_color; }
 1110 BlendMode blendMode() const { return m_blendMode; }
 1111
 1112private:
 1113 FillRoundedRect(const FloatRoundedRect& rect, const Color& color, BlendMode blendMode)
 1114 : DrawingItem(ItemType::FillRoundedRect)
 1115 , m_rect(rect)
 1116 , m_color(color)
 1117 , m_blendMode(blendMode)
 1118 {
 1119 }
 1120
 1121 virtual void apply(GraphicsContext&) const override;
 1122 virtual Optional<FloatRect> localBounds(const GraphicsContext&) const override { return m_rect.rect(); }
 1123
 1124 FloatRoundedRect m_rect;
 1125 Color m_color;
 1126 BlendMode m_blendMode;
 1127};
 1128
 1129class FillRectWithRoundedHole : public DrawingItem {
 1130public:
 1131 static Ref<FillRectWithRoundedHole> create(const FloatRect& rect, const FloatRoundedRect& roundedHoleRect, const Color& color)
 1132 {
 1133 return adoptRef(*new FillRectWithRoundedHole(rect, roundedHoleRect, color));
 1134 }
 1135
 1136 const FloatRect& rect() const { return m_rect; }
 1137 const FloatRoundedRect& roundedHoleRect() const { return m_roundedHoleRect; }
 1138 Color color() const { return m_color; }
 1139
 1140private:
 1141 FillRectWithRoundedHole(const FloatRect& rect, const FloatRoundedRect& roundedHoleRect, const Color& color)
 1142 : DrawingItem(ItemType::FillRectWithRoundedHole)
 1143 , m_rect(rect)
 1144 , m_roundedHoleRect(roundedHoleRect)
 1145 , m_color(color)
 1146 {
 1147 }
 1148
 1149 virtual void apply(GraphicsContext&) const override;
 1150 virtual Optional<FloatRect> localBounds(const GraphicsContext&) const override { return m_rect; }
 1151
 1152 FloatRect m_rect;
 1153 FloatRoundedRect m_roundedHoleRect;
 1154 Color m_color;
 1155};
 1156
 1157class FillPath : public DrawingItem {
 1158public:
 1159 static Ref<FillPath> create(const Path& path)
 1160 {
 1161 return adoptRef(*new FillPath(path));
 1162 }
 1163
 1164 const Path& path() const { return m_path; }
 1165
 1166private:
 1167 FillPath(const Path& path)
 1168 : DrawingItem(ItemType::FillPath)
 1169 , m_path(path)
 1170 {
 1171 }
 1172
 1173 virtual void apply(GraphicsContext&) const override;
 1174 virtual Optional<FloatRect> localBounds(const GraphicsContext&) const override { return m_path.fastBoundingRect(); }
 1175
 1176 Path m_path;
 1177};
 1178
 1179class FillEllipse : public DrawingItem {
 1180public:
 1181 static Ref<FillEllipse> create(const FloatRect& rect)
 1182 {
 1183 return adoptRef(*new FillEllipse(rect));
 1184 }
 1185
 1186 FloatRect rect() const { return m_rect; }
 1187
 1188private:
 1189 FillEllipse(const FloatRect& rect)
 1190 : DrawingItem(ItemType::FillEllipse)
 1191 , m_rect(rect)
 1192 {
 1193 }
 1194
 1195 virtual void apply(GraphicsContext&) const override;
 1196
 1197 virtual Optional<FloatRect> localBounds(const GraphicsContext&) const override { return m_rect; }
 1198
 1199 FloatRect m_rect;
 1200};
 1201
 1202class StrokeRect : public DrawingItem {
 1203public:
 1204 static Ref<StrokeRect> create(const FloatRect& rect, float lineWidth)
 1205 {
 1206 return adoptRef(*new StrokeRect(rect, lineWidth));
 1207 }
 1208
 1209 FloatRect rect() const { return m_rect; }
 1210 float lineWidth() const { return m_lineWidth; }
 1211
 1212private:
 1213 StrokeRect(const FloatRect& rect, float lineWidth)
 1214 : DrawingItem(ItemType::StrokeRect)
 1215 , m_rect(rect)
 1216 , m_lineWidth(lineWidth)
 1217 {
 1218 }
 1219
 1220 virtual void apply(GraphicsContext&) const override;
 1221 virtual Optional<FloatRect> localBounds(const GraphicsContext&) const override;
 1222
 1223 FloatRect m_rect;
 1224 float m_lineWidth;
 1225};
 1226
 1227class StrokePath : public DrawingItem {
 1228public:
 1229 static Ref<StrokePath> create(const Path& path, const FloatPoint& m_blockLocation)
 1230 {
 1231 return adoptRef(*new StrokePath(path, m_blockLocation));
 1232 }
 1233
 1234 void setBlockLocation(const FloatPoint& blockLocation) { m_blockLocation = blockLocation; }
 1235 const FloatPoint& blockLocation() const { return m_blockLocation; }
 1236 const Path& path() const { return m_path; }
 1237
 1238private:
 1239 StrokePath(const Path& path, const FloatPoint& blockLocation)
 1240 : DrawingItem(ItemType::StrokePath)
 1241 , m_path(path)
 1242 , m_blockLocation(blockLocation)
 1243 {
 1244 }
 1245
 1246 virtual void apply(GraphicsContext&) const override;
 1247 virtual Optional<FloatRect> localBounds(const GraphicsContext&) const override;
 1248
 1249 mutable Path m_path;
 1250 FloatPoint m_blockLocation;
 1251};
 1252
 1253class StrokeEllipse : public DrawingItem {
 1254public:
 1255 static Ref<StrokeEllipse> create(const FloatRect& rect)
 1256 {
 1257 return adoptRef(*new StrokeEllipse(rect));
 1258 }
 1259
 1260 FloatRect rect() const { return m_rect; }
 1261
 1262private:
 1263 StrokeEllipse(const FloatRect& rect)
 1264 : DrawingItem(ItemType::StrokeEllipse)
 1265 , m_rect(rect)
 1266 {
 1267 }
 1268
 1269 virtual void apply(GraphicsContext&) const override;
 1270 virtual Optional<FloatRect> localBounds(const GraphicsContext&) const override;
 1271
 1272 FloatRect m_rect;
 1273};
 1274
 1275class ClearRect : public DrawingItem {
 1276public:
 1277 static Ref<ClearRect> create(const FloatRect& rect)
 1278 {
 1279 return adoptRef(*new ClearRect(rect));
 1280 }
 1281
 1282 FloatRect rect() const { return m_rect; }
 1283
 1284private:
 1285 ClearRect(const FloatRect& rect)
 1286 : DrawingItem(ItemType::ClearRect)
 1287 , m_rect(rect)
 1288 {
 1289 }
 1290
 1291 virtual void apply(GraphicsContext&) const override;
 1292 virtual Optional<FloatRect> localBounds(const GraphicsContext&) const override { return m_rect; }
 1293
 1294 FloatRect m_rect;
 1295};
 1296
 1297class ApplyStrokePattern : public Item {
 1298public:
 1299 static Ref<ApplyStrokePattern> create()
 1300 {
 1301 return adoptRef(*new ApplyStrokePattern);
 1302 }
 1303
 1304private:
 1305 ApplyStrokePattern()
 1306 : Item(ItemType::ApplyStrokePattern)
 1307 {
 1308 }
 1309
 1310 virtual void apply(GraphicsContext&) const override;
 1311};
 1312
 1313class ApplyFillPattern : public Item {
 1314public:
 1315 static Ref<ApplyFillPattern> create()
 1316 {
 1317 return adoptRef(*new ApplyFillPattern);
 1318 }
 1319
 1320private:
 1321 ApplyFillPattern()
 1322 : Item(ItemType::ApplyFillPattern)
 1323 {
 1324 }
 1325
 1326 virtual void apply(GraphicsContext&) const override;
 1327};
 1328
 1329
 1330class ApplyDeviceScaleFactor : public Item {
 1331public:
 1332 static Ref<ApplyDeviceScaleFactor> create(float scaleFactor)
 1333 {
 1334 return adoptRef(*new ApplyDeviceScaleFactor(scaleFactor));
 1335 }
 1336
 1337 float scaleFactor() const { return m_scaleFactor; }
 1338
 1339private:
 1340 ApplyDeviceScaleFactor(float scaleFactor)
 1341 : Item(ItemType::ApplyDeviceScaleFactor)
 1342 , m_scaleFactor(scaleFactor)
 1343 {
 1344 }
 1345
 1346 virtual void apply(GraphicsContext&) const override;
 1347
 1348 float m_scaleFactor;
 1349};
 1350
 1351// FIXME: this needs to move.
 1352void addConvexPolygonToPath(Path&, size_t numPoints, const FloatPoint*);
 1353
 1354TextStream& operator<<(TextStream&, const Item&);
 1355
 1356} // namespace DisplayList
 1357} // namespace WebCore
 1358
 1359
 1360#define SPECIALIZE_TYPE_TRAITS_DISPLAYLIST_DRAWINGITEM(ToValueTypeName, predicate) \
 1361SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::DisplayList::ToValueTypeName) \
 1362 static bool isType(const WebCore::DisplayList::Item& object) { return object.predicate; } \
 1363SPECIALIZE_TYPE_TRAITS_END()
 1364
 1365SPECIALIZE_TYPE_TRAITS_DISPLAYLIST_DRAWINGITEM(DrawingItem, isDrawingItem())
 1366
 1367#define SPECIALIZE_TYPE_TRAITS_DISPLAYLIST_ITEM(ToValueTypeName) \
 1368SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::DisplayList::ToValueTypeName) \
 1369 static bool isType(const WebCore::DisplayList::Item& item) { return item.type() == WebCore::DisplayList::ItemType::ToValueTypeName; } \
 1370SPECIALIZE_TYPE_TRAITS_END()
 1371
 1372SPECIALIZE_TYPE_TRAITS_DISPLAYLIST_ITEM(Save)
 1373SPECIALIZE_TYPE_TRAITS_DISPLAYLIST_ITEM(Restore)
 1374SPECIALIZE_TYPE_TRAITS_DISPLAYLIST_ITEM(Translate)
 1375SPECIALIZE_TYPE_TRAITS_DISPLAYLIST_ITEM(Rotate)
 1376SPECIALIZE_TYPE_TRAITS_DISPLAYLIST_ITEM(Scale)
 1377SPECIALIZE_TYPE_TRAITS_DISPLAYLIST_ITEM(ConcatenateCTM)
 1378SPECIALIZE_TYPE_TRAITS_DISPLAYLIST_ITEM(SetState)
 1379SPECIALIZE_TYPE_TRAITS_DISPLAYLIST_ITEM(SetLineCap)
 1380SPECIALIZE_TYPE_TRAITS_DISPLAYLIST_ITEM(SetLineDash)
 1381SPECIALIZE_TYPE_TRAITS_DISPLAYLIST_ITEM(SetLineJoin)
 1382SPECIALIZE_TYPE_TRAITS_DISPLAYLIST_ITEM(SetMiterLimit)
 1383SPECIALIZE_TYPE_TRAITS_DISPLAYLIST_ITEM(Clip)
 1384SPECIALIZE_TYPE_TRAITS_DISPLAYLIST_ITEM(ClipOut)
 1385SPECIALIZE_TYPE_TRAITS_DISPLAYLIST_ITEM(ClipOutToPath)
 1386SPECIALIZE_TYPE_TRAITS_DISPLAYLIST_ITEM(ClipPath)
 1387SPECIALIZE_TYPE_TRAITS_DISPLAYLIST_ITEM(ClipConvexPolygon)
 1388SPECIALIZE_TYPE_TRAITS_DISPLAYLIST_ITEM(DrawGlyphs)
 1389SPECIALIZE_TYPE_TRAITS_DISPLAYLIST_ITEM(DrawImage)
 1390SPECIALIZE_TYPE_TRAITS_DISPLAYLIST_ITEM(DrawTiledImage)
 1391SPECIALIZE_TYPE_TRAITS_DISPLAYLIST_ITEM(DrawTiledScaledImage)
 1392SPECIALIZE_TYPE_TRAITS_DISPLAYLIST_ITEM(DrawNativeImage)
 1393SPECIALIZE_TYPE_TRAITS_DISPLAYLIST_ITEM(DrawPattern)
 1394SPECIALIZE_TYPE_TRAITS_DISPLAYLIST_ITEM(DrawRect)
 1395SPECIALIZE_TYPE_TRAITS_DISPLAYLIST_ITEM(DrawLine)
 1396SPECIALIZE_TYPE_TRAITS_DISPLAYLIST_ITEM(DrawLinesForText)
 1397SPECIALIZE_TYPE_TRAITS_DISPLAYLIST_ITEM(DrawLineForDocumentMarker)
 1398SPECIALIZE_TYPE_TRAITS_DISPLAYLIST_ITEM(DrawEllipse)
 1399SPECIALIZE_TYPE_TRAITS_DISPLAYLIST_ITEM(DrawConvexPolygon)
 1400SPECIALIZE_TYPE_TRAITS_DISPLAYLIST_ITEM(DrawPath)
 1401SPECIALIZE_TYPE_TRAITS_DISPLAYLIST_ITEM(DrawFocusRingPath)
 1402SPECIALIZE_TYPE_TRAITS_DISPLAYLIST_ITEM(DrawFocusRingRects)
 1403SPECIALIZE_TYPE_TRAITS_DISPLAYLIST_ITEM(FillRect)
 1404SPECIALIZE_TYPE_TRAITS_DISPLAYLIST_ITEM(FillRectWithColor)
 1405SPECIALIZE_TYPE_TRAITS_DISPLAYLIST_ITEM(FillRectWithGradient)
 1406SPECIALIZE_TYPE_TRAITS_DISPLAYLIST_ITEM(FillCompositedRect)
 1407SPECIALIZE_TYPE_TRAITS_DISPLAYLIST_ITEM(FillRoundedRect)
 1408SPECIALIZE_TYPE_TRAITS_DISPLAYLIST_ITEM(FillRectWithRoundedHole)
 1409SPECIALIZE_TYPE_TRAITS_DISPLAYLIST_ITEM(FillPath)
 1410SPECIALIZE_TYPE_TRAITS_DISPLAYLIST_ITEM(FillEllipse)
 1411SPECIALIZE_TYPE_TRAITS_DISPLAYLIST_ITEM(StrokeRect)
 1412SPECIALIZE_TYPE_TRAITS_DISPLAYLIST_ITEM(StrokePath)
 1413SPECIALIZE_TYPE_TRAITS_DISPLAYLIST_ITEM(StrokeEllipse)
 1414SPECIALIZE_TYPE_TRAITS_DISPLAYLIST_ITEM(ClearRect)
 1415SPECIALIZE_TYPE_TRAITS_DISPLAYLIST_ITEM(BeginTransparencyLayer)
 1416SPECIALIZE_TYPE_TRAITS_DISPLAYLIST_ITEM(EndTransparencyLayer)
 1417SPECIALIZE_TYPE_TRAITS_DISPLAYLIST_ITEM(ApplyStrokePattern)
 1418SPECIALIZE_TYPE_TRAITS_DISPLAYLIST_ITEM(ApplyFillPattern)
 1419SPECIALIZE_TYPE_TRAITS_DISPLAYLIST_ITEM(ApplyDeviceScaleFactor)
 1420SPECIALIZE_TYPE_TRAITS_DISPLAYLIST_ITEM(ClearShadow)
 1421
 1422#endif // DisplayListItems_h

Source/WebCore/platform/graphics/displaylists/DisplayListRecorder.cpp

 1/*
 2 * Copyright (C) 2015 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 "DisplayListRecorder.h"
 28
 29#include "DisplayList.h"
 30#include "DisplayListItems.h"
 31#include "GraphicsContext.h"
 32#include "Logging.h"
 33#include "TextStream.h"
 34#include <wtf/MathExtras.h>
 35
 36namespace WebCore {
 37namespace DisplayList {
 38
 39Recorder::Recorder(GraphicsContext& context, DisplayList& displayList, const FloatRect& initialClip, const AffineTransform& baseCTM)
 40 : m_graphicsContext(context)
 41 , m_displayList(displayList)
 42{
 43 LOG_WITH_STREAM(DisplayLists, stream << "\nRecording with clip " << initialClip);
 44
 45 // FIXME: hook up recorder in the GraphicsContext.
 46 // m_graphicsContext.setDisplayListRecorder(this);
 47 m_stateStack.append(ContextState(baseCTM, initialClip));
 48}
 49
 50Recorder::~Recorder()
 51{
 52 ASSERT(m_stateStack.size() == 1); // If this fires, it indicates mismatched save/restore.
 53 LOG(DisplayLists, "Recorded display list:\n%s", m_displayList.description().data());
 54}
 55
 56void Recorder::willAppendItem(const Item& item)
 57{
 58 if (item.isDrawingItem() || item.type() == ItemType::ApplyStrokePattern || item.type() == ItemType::ApplyStrokePattern) {
 59 GraphicsContextStateChange& stateChanges = currentState().stateChange;
 60 GraphicsContextState::StateChangeFlags changesFromLastState = stateChanges.changesFromState(currentState().lastDrawingState);
 61 if (changesFromLastState) {
 62 LOG_WITH_STREAM(DisplayLists, stream << "pre-drawing, saving state " << GraphicsContextStateChange(stateChanges.m_state, changesFromLastState));
 63 m_displayList.append(SetState::create(stateChanges.m_state, changesFromLastState));
 64 stateChanges.m_changeFlags = 0;
 65 currentState().lastDrawingState = stateChanges.m_state;
 66 }
 67 currentState().wasUsedForDrawing = true;
 68 }
 69}
 70
 71void Recorder::updateState(const GraphicsContextState& state, GraphicsContextState::StateChangeFlags flags)
 72{
 73 currentState().stateChange.accumulate(state, flags);
 74}
 75
 76void Recorder::clearShadow()
 77{
 78 appendItem(ClearShadow::create());
 79}
 80
 81void Recorder::setLineCap(LineCap lineCap)
 82{
 83 appendItem(SetLineCap::create(lineCap));
 84}
 85
 86void Recorder::setLineDash(const DashArray& dashArray, float dashOffset)
 87{
 88 appendItem(SetLineDash::create(dashArray, dashOffset));
 89}
 90
 91void Recorder::setLineJoin(LineJoin lineJoin)
 92{
 93 appendItem(SetLineJoin::create(lineJoin));
 94}
 95
 96void Recorder::setMiterLimit(float miterLimit)
 97{
 98 appendItem(SetMiterLimit::create(miterLimit));
 99}
 100
 101void Recorder::drawGlyphs(const Font& font, const GlyphBuffer& glyphBuffer, int from, int numGlyphs, const FloatPoint& startPoint, FontSmoothingMode smoothingMode)
 102{
 103 FloatPoint blockLocation = m_caching ? m_blockLocation : FloatPoint();
 104 FloatSize localAnchor = startPoint - blockLocation;
 105 DrawingItem& newItem = downcast<DrawingItem>(appendItem(DrawGlyphs::create(font, glyphBuffer.glyphs(from), glyphBuffer.advances(from), numGlyphs, blockLocation, localAnchor, smoothingMode)));
 106 updateItemExtent(newItem);
 107}
 108
 109void Recorder::drawImage(Image& image, const FloatRect& destination, const FloatRect& source, const ImagePaintingOptions& imagePaintingOptions)
 110{
 111 DrawingItem& newItem = downcast<DrawingItem>(appendItem(DrawImage::create(image, destination, source, imagePaintingOptions)));
 112 updateItemExtent(newItem);
 113}
 114
 115void Recorder::drawTiledImage(Image& image, const FloatRect& destination, const FloatPoint& source, const FloatSize& tileSize, const FloatSize& spacing, const ImagePaintingOptions& imagePaintingOptions)
 116{
 117 DrawingItem& newItem = downcast<DrawingItem>(appendItem(DrawTiledImage::create(image, destination, source, tileSize, spacing, imagePaintingOptions)));
 118 updateItemExtent(newItem);
 119}
 120
 121void Recorder::drawNativeImage(PassNativeImagePtr imagePtr, const FloatSize& imageSize, const FloatRect& destRect, const FloatRect& srcRect, CompositeOperator op, BlendMode blendMode, ImageOrientation orientation)
 122{
 123 DrawingItem& newItem = downcast<DrawingItem>(appendItem(DrawNativeImage::create(imagePtr, imageSize, destRect, srcRect, op, blendMode, orientation)));
 124 updateItemExtent(newItem);
 125}
 126
 127void Recorder::drawTiledImage(Image& image, const FloatRect& destination, const FloatRect& source, const FloatSize& tileScaleFactor, Image::TileRule hRule, Image::TileRule vRule, const ImagePaintingOptions& imagePaintingOptions)
 128{
 129 DrawingItem& newItem = downcast<DrawingItem>(appendItem(DrawTiledScaledImage::create(image, destination, source, tileScaleFactor, hRule, vRule, imagePaintingOptions)));
 130 updateItemExtent(newItem);
 131}
 132
 133void Recorder::drawPattern(Image& image, const FloatRect& tileRect, const AffineTransform& patternTransform, const FloatPoint& phase, const FloatSize& spacing, CompositeOperator op, const FloatRect& destRect, BlendMode blendMode)
 134{
 135 DrawingItem& newItem = downcast<DrawingItem>(appendItem(DrawPattern::create(image, tileRect, patternTransform, phase, spacing, op, destRect, blendMode)));
 136 updateItemExtent(newItem);
 137}
 138
 139void Recorder::save()
 140{
 141 appendItem(Save::create());
 142 m_stateStack.append(m_stateStack.last().cloneForSave(m_displayList.size() - 1));
 143}
 144
 145void Recorder::restore()
 146{
 147 if (!m_stateStack.size())
 148 return;
 149
 150 bool stateUsedForDrawing = currentState().wasUsedForDrawing;
 151 size_t saveIndex = currentState().saveItemIndex;
 152
 153 m_stateStack.removeLast();
 154 // Have to avoid eliding nested Save/Restore when a descendant state contains drawing items.
 155 currentState().wasUsedForDrawing |= stateUsedForDrawing;
 156
 157 if (!stateUsedForDrawing && saveIndex) {
 158 // This Save/Restore didn't contain any drawing items. Roll back to just before the last save.
 159 m_displayList.removeItemsFromIndex(saveIndex);
 160 return;
 161 }
 162
 163 appendItem(Restore::create());
 164
 165 if (saveIndex) {
 166 Save& saveItem = downcast<Save>(m_displayList.itemAt(saveIndex));
 167 saveItem.setRestoreIndex(m_displayList.size() - 1);
 168 }
 169}
 170
 171void Recorder::translate(float x, float y)
 172{
 173 currentState().translate(x, y);
 174 appendItem(Translate::create(x, y));
 175}
 176
 177void Recorder::rotate(float angleInRadians)
 178{
 179 currentState().rotate(angleInRadians);
 180 appendItem(Rotate::create(angleInRadians));
 181}
 182
 183void Recorder::scale(const FloatSize& size)
 184{
 185 currentState().scale(size);
 186 appendItem(Scale::create(size));
 187}
 188
 189void Recorder::concatCTM(const AffineTransform& transform)
 190{
 191 currentState().concatCTM(transform);
 192 appendItem(ConcatenateCTM::create(transform));
 193}
 194
 195void Recorder::beginTransparencyLayer(float opacity)
 196{
 197 DrawingItem& newItem = downcast<DrawingItem>(appendItem(BeginTransparencyLayer::create(opacity)));
 198 updateItemExtent(newItem);
 199}
 200
 201void Recorder::endTransparencyLayer()
 202{
 203 appendItem(EndTransparencyLayer::create());
 204}
 205
 206void Recorder::drawRect(const FloatRect& rect, float borderThickness)
 207{
 208 DrawingItem& newItem = downcast<DrawingItem>(appendItem(DrawRect::create(rect, borderThickness)));
 209 updateItemExtent(newItem);
 210}
 211
 212void Recorder::drawLine(const FloatPoint& point1, const FloatPoint& point2)
 213{
 214 DrawingItem& newItem = downcast<DrawingItem>(appendItem(DrawLine::create(point1, point2)));
 215 updateItemExtent(newItem);
 216}
 217
 218void Recorder::drawLinesForText(const FloatPoint& point, const DashArray& widths, bool printing, bool doubleLines, float strokeThickness)
 219{
 220 FloatPoint blockLocation = m_caching ? m_blockLocation : FloatPoint();
 221 FloatSize localAnchor = point - blockLocation;
 222 DrawingItem& newItem = downcast<DrawingItem>(appendItem(DrawLinesForText::create(blockLocation, localAnchor, widths, printing, doubleLines, strokeThickness)));
 223 updateItemExtent(newItem);
 224}
 225
 226void Recorder::drawLineForDocumentMarker(const FloatPoint& point, float width, GraphicsContext::DocumentMarkerLineStyle style)
 227{
 228 DrawingItem& newItem = downcast<DrawingItem>(appendItem(DrawLineForDocumentMarker::create(point, width, style)));
 229 updateItemExtent(newItem);
 230}
 231
 232void Recorder::drawEllipse(const FloatRect& rect)
 233{
 234 DrawingItem& newItem = downcast<DrawingItem>(appendItem(DrawEllipse::create(rect)));
 235 updateItemExtent(newItem);
 236}
 237
 238void Recorder::drawConvexPolygon(size_t numberOfPoints, const FloatPoint* points, bool antialiased)
 239{
 240 DrawingItem& newItem = downcast<DrawingItem>(appendItem(DrawConvexPolygon::create(numberOfPoints, points, antialiased)));
 241 updateItemExtent(newItem);
 242}
 243
 244void Recorder::drawPath(const Path& path)
 245{
 246 DrawingItem& newItem = downcast<DrawingItem>(appendItem(DrawPath::create(path)));
 247 updateItemExtent(newItem);
 248}
 249
 250void Recorder::drawFocusRing(const Path& path, int width, int offset, const Color& color)
 251{
 252 DrawingItem& newItem = downcast<DrawingItem>(appendItem(DrawFocusRingPath::create(path, width, offset, color)));
 253 updateItemExtent(newItem);
 254}
 255
 256void Recorder::drawFocusRing(const Vector<IntRect>& rects, int width, int offset, const Color& color)
 257{
 258 DrawingItem& newItem = downcast<DrawingItem>(appendItem(DrawFocusRingRects::create(rects, width, offset, color)));
 259 updateItemExtent(newItem);
 260}
 261
 262void Recorder::fillRect(const FloatRect& rect)
 263{
 264 DrawingItem& newItem = downcast<DrawingItem>(appendItem(FillRect::create(rect)));
 265 updateItemExtent(newItem);
 266}
 267
 268void Recorder::fillRect(const FloatRect& rect, const Color& color)
 269{
 270 DrawingItem& newItem = downcast<DrawingItem>(appendItem(FillRectWithColor::create(rect, color)));
 271 updateItemExtent(newItem);
 272}
 273
 274void Recorder::fillRect(const FloatRect& rect, Gradient& gradient)
 275{
 276 DrawingItem& newItem = downcast<DrawingItem>(appendItem(FillRectWithGradient::create(rect, gradient)));
 277 updateItemExtent(newItem);
 278}
 279
 280void Recorder::fillRect(const FloatRect& rect, const Color& color, CompositeOperator op, BlendMode blendMode)
 281{
 282 DrawingItem& newItem = downcast<DrawingItem>(appendItem(FillCompositedRect::create(rect, color, op, blendMode)));
 283 updateItemExtent(newItem);
 284}
 285
 286void Recorder::fillRoundedRect(const FloatRoundedRect& rect, const Color& color, BlendMode blendMode)
 287{
 288 DrawingItem& newItem = downcast<DrawingItem>(appendItem(FillRoundedRect::create(rect, color, blendMode)));
 289 updateItemExtent(newItem);
 290}
 291
 292void Recorder::fillRectWithRoundedHole(const FloatRect& rect, const FloatRoundedRect& roundedHoleRect, const Color& color)
 293{
 294 DrawingItem& newItem = downcast<DrawingItem>(appendItem(FillRectWithRoundedHole::create(rect, roundedHoleRect, color)));
 295 updateItemExtent(newItem);
 296}
 297
 298void Recorder::fillPath(const Path& path)
 299{
 300 DrawingItem& newItem = downcast<DrawingItem>(appendItem(FillPath::create(path)));
 301 updateItemExtent(newItem);
 302}
 303
 304void Recorder::fillEllipse(const FloatRect& rect)
 305{
 306 DrawingItem& newItem = downcast<DrawingItem>(appendItem(FillEllipse::create(rect)));
 307 updateItemExtent(newItem);
 308}
 309
 310void Recorder::strokeRect(const FloatRect& rect, float lineWidth)
 311{
 312 DrawingItem& newItem = downcast<DrawingItem>(appendItem(StrokeRect::create(rect, lineWidth)));
 313 updateItemExtent(newItem);
 314}
 315
 316void Recorder::strokePath(const Path& path)
 317{
 318 FloatPoint blockLocation = m_caching ? m_blockLocation : FloatPoint();
 319 Path translated = path;
 320 translated.translate(-FloatSize(blockLocation.x(), blockLocation.y()));
 321 DrawingItem& newItem = downcast<DrawingItem>(appendItem(StrokePath::create(path, blockLocation)));
 322 updateItemExtent(newItem);
 323}
 324
 325void Recorder::strokeEllipse(const FloatRect& rect)
 326{
 327 DrawingItem& newItem = downcast<DrawingItem>(appendItem(StrokeEllipse::create(rect)));
 328 updateItemExtent(newItem);
 329}
 330
 331void Recorder::clearRect(const FloatRect& rect)
 332{
 333 DrawingItem& newItem = downcast<DrawingItem>(appendItem(ClearRect::create(rect)));
 334 updateItemExtent(newItem);
 335}
 336
 337void Recorder::applyStrokePattern()
 338{
 339 appendItem(ApplyStrokePattern::create());
 340}
 341
 342void Recorder::applyFillPattern()
 343{
 344 appendItem(ApplyFillPattern::create());
 345}
 346
 347void Recorder::clip(const FloatRect& rect)
 348{
 349 currentState().clipBounds.intersect(rect);
 350 appendItem(Clip::create(rect));
 351}
 352
 353void Recorder::clipOut(const FloatRect& rect)
 354{
 355 appendItem(ClipOut::create(rect));
 356}
 357
 358void Recorder::clipOut(const Path& path)
 359{
 360 appendItem(ClipOutToPath::create(path));
 361}
 362
 363void Recorder::clipPath(const Path& path, WindRule windRule)
 364{
 365 currentState().clipBounds.intersect(path.fastBoundingRect());
 366 appendItem(ClipPath::create(path, windRule));
 367}
 368
 369void Recorder::clipConvexPolygon(size_t numPoints, const FloatPoint* points, bool antialias)
 370{
 371 Path polygonPath;
 372 addConvexPolygonToPath(polygonPath, numPoints, points);
 373 currentState().clipBounds.intersect(polygonPath.fastBoundingRect());
 374
 375 appendItem(ClipConvexPolygon::create(numPoints, points, antialias));
 376}
 377
 378void Recorder::applyDeviceScaleFactor(float deviceScaleFactor)
 379{
 380 // FIXME: this changes the baseCTM, which will invalidate all of our cached extents.
 381 // Assert that it's only called early on?
 382 appendItem(ApplyDeviceScaleFactor::create(deviceScaleFactor));
 383}
 384
 385Item& Recorder::appendItem(Ref<Item>&& item)
 386{
 387 willAppendItem(item.get());
 388 return m_displayList.append(WTFMove(item));
 389}
 390
 391void Recorder::updateItemExtent(DrawingItem& item) const
 392{
 393 if (Optional<FloatRect> rect = item.localBounds(m_graphicsContext))
 394 item.setExtent(extentFromLocalBounds(rect.value()));
 395}
 396
 397// FIXME: share with ShadowData
 398static inline float shadowPaintingExtent(float blurRadius)
 399{
 400 // Blurring uses a Gaussian function whose std. deviation is m_radius/2, and which in theory
 401 // extends to infinity. In 8-bit contexts, however, rounding causes the effect to become
 402 // undetectable at around 1.4x the radius.
 403 const float radiusExtentMultiplier = 1.4;
 404 return ceilf(blurRadius * radiusExtentMultiplier);
 405}
 406
 407FloatRect Recorder::extentFromLocalBounds(const FloatRect& rect) const
 408{
 409 FloatRect bounds = rect;
 410 const ContextState& state = currentState();
 411
 412 FloatSize shadowOffset;
 413 float shadowRadius;
 414 Color shadowColor;
 415 if (m_graphicsContext.getShadow(shadowOffset, shadowRadius, shadowColor)) {
 416 FloatRect shadowExtent= bounds;
 417 shadowExtent.move(shadowOffset);
 418 shadowExtent.inflate(shadowPaintingExtent(shadowRadius));
 419 bounds.unite(shadowExtent);
 420 }
 421
 422 FloatRect clippedExtent = intersection(state.clipBounds, bounds);
 423 return state.ctm.mapRect(clippedExtent);
 424}
 425
 426const Recorder::ContextState& Recorder::currentState() const
 427{
 428 ASSERT(m_stateStack.size());
 429 return m_stateStack.last();
 430}
 431
 432Recorder::ContextState& Recorder::currentState()
 433{
 434 ASSERT(m_stateStack.size());
 435 return m_stateStack.last();
 436}
 437
 438const AffineTransform& Recorder::ctm() const
 439{
 440 return currentState().ctm;
 441}
 442
 443const FloatRect& Recorder::clipBounds() const
 444{
 445 return currentState().clipBounds;
 446}
 447
 448void Recorder::ContextState::translate(float x, float y)
 449{
 450 ctm.translate(x, y);
 451 clipBounds.move(-x, -y);
 452}
 453
 454void Recorder::ContextState::rotate(float angleInRadians)
 455{
 456 double angleInDegrees = rad2deg(static_cast<double>(angleInRadians));
 457 ctm.rotate(angleInDegrees);
 458
 459 AffineTransform rotation;
 460 rotation.rotate(angleInDegrees);
 461
 462 if (Optional<AffineTransform> inverse = rotation.inverse())
 463 clipBounds = inverse.value().mapRect(clipBounds);
 464}
 465
 466void Recorder::ContextState::scale(const FloatSize& size)
 467{
 468 ctm.scale(size);
 469 clipBounds.scale(1 / size.width(), 1 / size.height());
 470}
 471
 472void Recorder::ContextState::concatCTM(const AffineTransform& matrix)
 473{
 474 ctm *= matrix;
 475
 476 if (Optional<AffineTransform> inverse = matrix.inverse())
 477 clipBounds = inverse.value().mapRect(clipBounds);
 478}
 479
 480} // namespace DisplayList
 481} // namespace WebCore

Source/WebCore/platform/graphics/displaylists/DisplayListRecorder.h

 1/*
 2 * Copyright (C) 2015 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#ifndef DisplayListRecorder_h
 27#define DisplayListRecorder_h
 28
 29#include "DisplayList.h"
 30#include "GraphicsContext.h" // For InterpolationQuality.
 31#include "Image.h" // For Image::TileRule.
 32#include "TextFlags.h"
 33#include <wtf/Noncopyable.h>
 34
 35namespace WebCore {
 36
 37class FloatPoint;
 38class FloatRect;
 39class GlyphBuffer;
 40class FloatPoint;
 41class Font;
 42class Image;
 43
 44struct GraphicsContextState;
 45struct ImagePaintingOptions;
 46
 47namespace DisplayList {
 48
 49class DrawingItem;
 50
 51class Recorder {
 52 WTF_MAKE_NONCOPYABLE(Recorder);
 53public:
 54 Recorder(GraphicsContext&, DisplayList&, const FloatRect& initialClip, const AffineTransform&);
 55 ~Recorder();
 56
 57 void updateState(const GraphicsContextState&, GraphicsContextState::StateChangeFlags);
 58 void clearShadow();
 59
 60 void setLineCap(LineCap);
 61 void setLineDash(const DashArray&, float dashOffset);
 62 void setLineJoin(LineJoin);
 63 void setMiterLimit(float);
 64
 65 void fillRect(const FloatRect&);
 66 void fillRect(const FloatRect&, const Color&);
 67 void fillRect(const FloatRect&, Gradient&);
 68 void fillRect(const FloatRect&, const Color&, CompositeOperator, BlendMode);
 69 void fillRoundedRect(const FloatRoundedRect&, const Color&, BlendMode);
 70 void fillRectWithRoundedHole(const FloatRect&, const FloatRoundedRect& roundedHoleRect, const Color&);
 71 void fillPath(const Path&);
 72 void fillEllipse(const FloatRect&);
 73 void strokeRect(const FloatRect&, float lineWidth);
 74 void strokePath(const Path&);
 75 void strokeEllipse(const FloatRect&);
 76 void clearRect(const FloatRect&);
 77
 78 void applyStrokePattern();
 79 void applyFillPattern();
 80
 81 void drawGlyphs(const Font&, const GlyphBuffer&, int from, int numGlyphs, const FloatPoint& anchorPoint, FontSmoothingMode);
 82
 83 void drawImage(Image&, const FloatRect& destination, const FloatRect& source, const ImagePaintingOptions&);
 84 void drawTiledImage(Image&, const FloatRect& destination, const FloatPoint& source, const FloatSize& tileSize, const FloatSize& spacing, const ImagePaintingOptions&);
 85 void drawTiledImage(Image&, const FloatRect& destination, const FloatRect& source, const FloatSize& tileScaleFactor, Image::TileRule hRule, Image::TileRule vRule, const ImagePaintingOptions&);
 86 void drawNativeImage(PassNativeImagePtr, const FloatSize& selfSize, const FloatRect& destRect, const FloatRect& srcRect, CompositeOperator, BlendMode, ImageOrientation);
 87 void drawPattern(Image&, const FloatRect& srcRect, const AffineTransform&, const FloatPoint& phase, const FloatSize& spacing, CompositeOperator, const FloatRect& destRect, BlendMode = BlendModeNormal);
 88
 89 void drawRect(const FloatRect&, float borderThickness);
 90 void drawLine(const FloatPoint&, const FloatPoint&);
 91 void drawLinesForText(const FloatPoint&, const DashArray& widths, bool printing, bool doubleLines, float strokeThickness);
 92 void drawLineForDocumentMarker(const FloatPoint&, float width, GraphicsContext::DocumentMarkerLineStyle);
 93 void drawEllipse(const FloatRect&);
 94 void drawConvexPolygon(size_t numberOfPoints, const FloatPoint*, bool antialiased);
 95 void drawPath(const Path&);
 96
 97 void drawFocusRing(const Path&, int width, int offset, const Color&);
 98 void drawFocusRing(const Vector<IntRect>&, int width, int offset, const Color&);
 99
 100 void save();
 101 void restore();
 102
 103 void translate(float x, float y);
 104 void rotate(float angleInRadians);
 105 void scale(const FloatSize&);
 106 void concatCTM(const AffineTransform&);
 107
 108 void beginTransparencyLayer(float opacity);
 109 void endTransparencyLayer();
 110
 111 void clip(const FloatRect&);
 112 void clipOut(const FloatRect&);
 113 void clipOut(const Path&);
 114 void clipPath(const Path&, WindRule);
 115 void clipConvexPolygon(size_t numPoints, const FloatPoint*, bool antialias);
 116
 117 void applyDeviceScaleFactor(float);
 118
 119 size_t size() const { return m_displayList.size(); }
 120
 121private:
 122 Item& appendItem(Ref<Item>&&);
 123 void willAppendItem(const Item&);
 124
 125 FloatRect extentFromLocalBounds(const FloatRect&) const;
 126 void updateItemExtent(DrawingItem&) const;
 127
 128 const AffineTransform& ctm() const;
 129 const FloatRect& clipBounds() const;
 130
 131 struct ContextState {
 132 AffineTransform ctm;
 133 FloatRect clipBounds;
 134 GraphicsContextStateChange stateChange;
 135 GraphicsContextState lastDrawingState;
 136 bool wasUsedForDrawing { false };
 137 size_t saveItemIndex { 0 };
 138
 139 ContextState(const AffineTransform& transform, const FloatRect& clip)
 140 : ctm(transform)
 141 , clipBounds(clip)
 142 {
 143 }
 144
 145 ContextState cloneForSave(size_t saveIndex) const
 146 {
 147 ContextState state(ctm, clipBounds);
 148 state.stateChange = stateChange;
 149 state.lastDrawingState = lastDrawingState;
 150 state.saveItemIndex = saveIndex;
 151 return state;
 152 }
 153
 154 void translate(float x, float y);
 155 void rotate(float angleInRadians);
 156 void scale(const FloatSize&);
 157 void concatCTM(const AffineTransform&);
 158 };
 159
 160 const ContextState& currentState() const;
 161 ContextState& currentState();
 162
 163 GraphicsContext& m_graphicsContext;
 164 DisplayList& m_displayList;
 165
 166 bool m_caching { false };
 167 FloatPoint m_blockLocation;
 168
 169 Vector<ContextState, 32> m_stateStack;
 170};
 171
 172}
 173}
 174
 175#endif // DisplayListRecorder_h

Source/WebCore/platform/graphics/displaylists/DisplayListReplayer.cpp

 1/*
 2 * Copyright (C) 2015 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 "DisplayListReplayer.h"
 28
 29#include "DisplayList.h"
 30#include "DisplayListItems.h"
 31#include "GraphicsContext.h"
 32#include "Logging.h"
 33#include "TextStream.h"
 34
 35namespace WebCore {
 36namespace DisplayList {
 37
 38Replayer::Replayer(GraphicsContext& context, const DisplayList& displayList)
 39 : m_displayList(displayList)
 40 , m_context(context)
 41{
 42}
 43
 44Replayer::~Replayer()
 45{
 46}
 47
 48void Replayer::replay(const FloatRect& initialClip)
 49{
 50 LOG_WITH_STREAM(DisplayLists, stream << "\nReplaying with clip " << initialClip);
 51 UNUSED_PARAM(initialClip);
 52
 53 size_t numItems = m_displayList.size();
 54 for (size_t i = 0; i < numItems; ++i) {
 55 auto& item = m_displayList.list()[i].get();
 56 LOG_WITH_STREAM(DisplayLists, stream << "drawing " << i << " " << item);
 57 item.apply(m_context);
 58 }
 59}
 60
 61} // namespace DisplayList
 62} // namespace WebCore

Source/WebCore/platform/graphics/displaylists/DisplayListReplayer.h

 1/*
 2 * Copyright (C) 2015 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#ifndef DisplayListReplayer_h
 27#define DisplayListReplayer_h
 28
 29#include <wtf/Noncopyable.h>
 30
 31namespace WebCore {
 32
 33class AffineTransform;
 34class FloatRect;
 35class GraphicsContext;
 36
 37namespace DisplayList {
 38
 39class DisplayList;
 40
 41class Replayer {
 42 WTF_MAKE_NONCOPYABLE(Replayer);
 43public:
 44 Replayer(GraphicsContext&, const DisplayList&);
 45 ~Replayer();
 46
 47 void replay(const FloatRect& initialClip);
 48
 49private:
 50 const DisplayList& m_displayList;
 51 GraphicsContext& m_context;
 52};
 53
 54}
 55}
 56
 57#endif // DisplayListReplayer_h