2 * Copyright (C) 2003, 2006, 2007, 2008, 2009, 2013 Apple Inc. All rights reserved.
3 * Copyright (C) 2008-2009 Torch Mobile, Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #ifndef GraphicsContext_h
28 #define GraphicsContext_h
30 #include "ColorSpace.h"
31 #include "DashArray.h"
32 #include "FloatRect.h"
36 #include "ImageOrientation.h"
39 #include <wtf/Noncopyable.h>
40 #include <wtf/PassOwnPtr.h>
43 typedef struct CGContext PlatformGraphicsContext;
46 class PlatformContextCairo;
48 typedef WebCore::PlatformContextCairo PlatformGraphicsContext;
50 typedef struct HDC__ PlatformGraphicsContext;
52 typedef void PlatformGraphicsContext;
56 #include "DIBPixelData.h"
57 typedef struct HDC__* HDC;
59 // UInt8 is defined in CoreFoundation/CFBase.h
60 typedef unsigned char UInt8;
72 const int cMisspellingLineThickness = 3;
73 const int cMisspellingLinePatternWidth = 4;
74 const int cMisspellingLinePatternGapWidth = 1;
76 class AffineTransform;
78 class FloatRoundedRect;
80 class GraphicsContextPlatformPrivate;
85 class GraphicsContext3D;
87 class TransformationMatrix;
92 enum TextDrawingMode {
93 TextModeFill = 1 << 0,
94 TextModeStroke = 1 << 1,
95 #if ENABLE(LETTERPRESS)
96 TextModeLetterpress = 1 << 2,
99 typedef unsigned TextDrawingModeFlags;
110 enum InterpolationQuality {
111 InterpolationDefault,
118 struct GraphicsContextState {
119 GraphicsContextState()
122 , textDrawingMode(TextModeFill)
123 , strokeColor(Color::black)
124 , fillColor(Color::black)
125 , strokeStyle(SolidStroke)
126 , fillRule(RULE_NONZERO)
127 , strokeColorSpace(ColorSpaceDeviceRGB)
128 , fillColorSpace(ColorSpaceDeviceRGB)
129 , shadowColorSpace(ColorSpaceDeviceRGB)
130 , compositeOperator(CompositeSourceOver)
131 , blendMode(BlendModeNormal)
133 , emojiDrawingEnabled(true)
134 , shouldUseContextColors(true)
136 , shouldAntialias(true)
137 , shouldSmoothFonts(true)
138 , shouldSubpixelQuantizeFonts(true)
139 , paintingDisabled(false)
140 , shadowsIgnoreTransforms(false)
142 // Core Graphics incorrectly renders shadows with radius > 8px (<rdar://problem/8103442>),
143 // but we need to preserve this buggy behavior for canvas and -webkit-box-shadow.
144 , shadowsUseLegacyRadius(false)
146 , drawLuminanceMask(false)
150 RefPtr<Gradient> strokeGradient;
151 RefPtr<Pattern> strokePattern;
153 RefPtr<Gradient> fillGradient;
154 RefPtr<Pattern> fillPattern;
156 FloatSize shadowOffset;
158 float strokeThickness;
161 TextDrawingModeFlags textDrawingMode;
167 StrokeStyle strokeStyle;
170 ColorSpace strokeColorSpace;
171 ColorSpace fillColorSpace;
172 ColorSpace shadowColorSpace;
174 CompositeOperator compositeOperator;
178 bool emojiDrawingEnabled : 1;
179 bool shouldUseContextColors : 1;
181 bool shouldAntialias : 1;
182 bool shouldSmoothFonts : 1;
183 bool shouldSubpixelQuantizeFonts : 1;
184 bool paintingDisabled : 1;
185 bool shadowsIgnoreTransforms : 1;
187 bool shadowsUseLegacyRadius : 1;
189 bool drawLuminanceMask : 1;
193 WEBCORE_EXPORT void setStrokeAndFillColor(PlatformGraphicsContext*, CGColorRef);
196 struct ImagePaintingOptions {
197 ImagePaintingOptions(CompositeOperator compositeOperator = CompositeSourceOver, BlendMode blendMode = BlendModeNormal, ImageOrientationDescription orientationDescription = ImageOrientationDescription(), bool useLowQualityScale = false)
198 : m_compositeOperator(compositeOperator)
199 , m_blendMode(blendMode)
200 , m_orientationDescription(orientationDescription)
201 , m_useLowQualityScale(useLowQualityScale)
205 ImagePaintingOptions(ImageOrientationDescription orientationDescription, bool useLowQualityScale = false, CompositeOperator compositeOperator = CompositeSourceOver, BlendMode blendMode = BlendModeNormal)
206 : m_compositeOperator(compositeOperator)
207 , m_blendMode(blendMode)
208 , m_orientationDescription(orientationDescription)
209 , m_useLowQualityScale(useLowQualityScale)
213 ImagePaintingOptions(bool useLowQualityScale, ImageOrientationDescription orientationDescription = ImageOrientationDescription(), CompositeOperator compositeOperator = CompositeSourceOver, BlendMode blendMode = BlendModeNormal)
214 : m_compositeOperator(compositeOperator)
215 , m_blendMode(blendMode)
216 , m_orientationDescription(orientationDescription)
217 , m_useLowQualityScale(useLowQualityScale)
221 CompositeOperator m_compositeOperator;
222 BlendMode m_blendMode;
223 ImageOrientationDescription m_orientationDescription;
224 bool m_useLowQualityScale;
227 class GraphicsContext {
228 WTF_MAKE_NONCOPYABLE(GraphicsContext); WTF_MAKE_FAST_ALLOCATED;
231 WEBCORE_EXPORT GraphicsContext(PlatformGraphicsContext*);
233 WEBCORE_EXPORT GraphicsContext(PlatformGraphicsContext*, bool shouldUseContextColors = true);
235 WEBCORE_EXPORT ~GraphicsContext();
237 WEBCORE_EXPORT PlatformGraphicsContext* platformContext() const;
239 float strokeThickness() const;
240 void setStrokeThickness(float);
241 StrokeStyle strokeStyle() const;
242 void setStrokeStyle(StrokeStyle);
243 Color strokeColor() const;
244 ColorSpace strokeColorSpace() const;
245 WEBCORE_EXPORT void setStrokeColor(const Color&, ColorSpace);
247 void setStrokePattern(PassRefPtr<Pattern>);
248 Pattern* strokePattern() const;
250 void setStrokeGradient(PassRefPtr<Gradient>);
251 Gradient* strokeGradient() const;
253 WindRule fillRule() const;
254 void setFillRule(WindRule);
255 Color fillColor() const;
256 ColorSpace fillColorSpace() const;
257 WEBCORE_EXPORT void setFillColor(const Color&, ColorSpace);
259 void setFillPattern(PassRefPtr<Pattern>);
260 Pattern* fillPattern() const;
262 WEBCORE_EXPORT void setFillGradient(PassRefPtr<Gradient>);
263 Gradient* fillGradient() const;
265 void setShadowsIgnoreTransforms(bool);
266 bool shadowsIgnoreTransforms() const;
268 WEBCORE_EXPORT void setShouldAntialias(bool);
269 bool shouldAntialias() const;
271 WEBCORE_EXPORT void setShouldSmoothFonts(bool);
272 bool shouldSmoothFonts() const;
274 // Normally CG enables subpixel-quantization because it improves the performance of aligning glyphs.
275 // In some cases we have to disable to to ensure a high-quality output of the glyphs.
276 void setShouldSubpixelQuantizeFonts(bool);
277 bool shouldSubpixelQuantizeFonts() const;
279 const GraphicsContextState& state() const;
282 void applyStrokePattern();
283 void applyFillPattern();
284 void drawPath(const Path&);
286 WEBCORE_EXPORT void drawNativeImage(PassNativeImagePtr, const FloatSize& selfSize, ColorSpace styleColorSpace, const FloatRect& destRect, const FloatRect& srcRect, CompositeOperator = CompositeSourceOver, BlendMode = BlendModeNormal, ImageOrientation = DefaultImageOrientation);
288 // Allow font smoothing (LCD antialiasing). Not part of the graphics state.
289 void setAllowsFontSmoothing(bool);
291 WEBCORE_EXPORT void setIsCALayerContext(bool);
292 bool isCALayerContext() const;
294 WEBCORE_EXPORT void setIsAcceleratedContext(bool);
296 bool isAcceleratedContext() const;
298 WEBCORE_EXPORT void save();
299 WEBCORE_EXPORT void restore();
301 // These draw methods will do both stroking and filling.
302 // FIXME: ...except drawRect(), which fills properly but always strokes
303 // using a 1-pixel stroke inset from the rect borders (of the correct
305 void drawRect(const FloatRect&, float borderThickness = 1);
306 void drawLine(const FloatPoint&, const FloatPoint&);
309 void drawJoinedLines(CGPoint points[], unsigned count, bool antialias, CGLineCap = kCGLineCapButt);
312 void drawEllipse(const FloatRect&);
313 void drawRaisedEllipse(const FloatRect&, const Color& ellipseColor, ColorSpace ellipseColorSpace, const Color& shadowColor, ColorSpace shadowColorSpace);
314 void drawConvexPolygon(size_t numPoints, const FloatPoint*, bool shouldAntialias = false);
316 WEBCORE_EXPORT void fillPath(const Path&);
317 void strokePath(const Path&);
319 void fillEllipse(const FloatRect&);
320 void strokeEllipse(const FloatRect&);
322 WEBCORE_EXPORT void fillRect(const FloatRect&);
323 WEBCORE_EXPORT void fillRect(const FloatRect&, const Color&, ColorSpace);
324 void fillRect(const FloatRect&, Gradient&);
325 void fillRect(const FloatRect&, const Color&, ColorSpace, CompositeOperator, BlendMode = BlendModeNormal);
326 void fillRoundedRect(const FloatRoundedRect&, const Color&, ColorSpace, BlendMode = BlendModeNormal);
327 void fillRectWithRoundedHole(const FloatRect&, const FloatRoundedRect& roundedHoleRect, const Color&, ColorSpace);
329 WEBCORE_EXPORT void clearRect(const FloatRect&);
331 WEBCORE_EXPORT void strokeRect(const FloatRect&, float lineWidth);
333 WEBCORE_EXPORT void drawImage(Image*, ColorSpace, const FloatPoint& destination, const ImagePaintingOptions& = ImagePaintingOptions());
334 void drawImage(Image*, ColorSpace, const FloatRect& destination, const ImagePaintingOptions& = ImagePaintingOptions());
335 void drawImage(Image*, ColorSpace, const FloatRect& destination, const FloatRect& source, const ImagePaintingOptions& = ImagePaintingOptions());
337 void drawTiledImage(Image*, ColorSpace, const FloatRect& destination, const FloatPoint& source, const FloatSize& tileSize,
338 const ImagePaintingOptions& = ImagePaintingOptions());
339 void drawTiledImage(Image*, ColorSpace, const FloatRect& destination, const FloatRect& source, const FloatSize& tileScaleFactor,
340 Image::TileRule, Image::TileRule, const ImagePaintingOptions& = ImagePaintingOptions());
342 void drawImageBuffer(ImageBuffer*, ColorSpace, const FloatPoint& destination, const ImagePaintingOptions& = ImagePaintingOptions());
343 void drawImageBuffer(ImageBuffer*, ColorSpace, const FloatRect& destination, const ImagePaintingOptions& = ImagePaintingOptions());
344 void drawImageBuffer(ImageBuffer*, ColorSpace, const FloatRect& destination, const FloatRect& source, const ImagePaintingOptions& = ImagePaintingOptions());
346 WEBCORE_EXPORT void setImageInterpolationQuality(InterpolationQuality);
347 InterpolationQuality imageInterpolationQuality() const;
349 WEBCORE_EXPORT void clip(const IntRect&);
350 WEBCORE_EXPORT void clip(const FloatRect&);
351 void clipRoundedRect(const FloatRoundedRect&);
353 void clipOut(const FloatRect&);
354 void clipOutRoundedRect(const FloatRoundedRect&);
355 void clipPath(const Path&, WindRule);
356 void clipConvexPolygon(size_t numPoints, const FloatPoint*, bool antialias = true);
357 void clipToImageBuffer(ImageBuffer*, const FloatRect&);
359 IntRect clipBounds() const;
361 TextDrawingModeFlags textDrawingMode() const;
362 void setTextDrawingMode(TextDrawingModeFlags);
365 bool emojiDrawingEnabled();
366 WEBCORE_EXPORT void setEmojiDrawingEnabled(bool);
370 void drawText(const Font&, const TextRun&, const FloatPoint&, int from = 0, int to = -1);
372 float drawText(const Font&, const TextRun&, const FloatPoint&, int from = 0, int to = -1);
374 void drawGlyphs(const Font&, const SimpleFontData&, const GlyphBuffer&, int from, int numGlyphs, const FloatPoint&);
375 void drawEmphasisMarks(const Font&, const TextRun& , const AtomicString& mark, const FloatPoint&, int from = 0, int to = -1);
377 void drawBidiText(const Font&, const TextRun&, const FloatPoint&, Font::CustomFontNotReadyAction = Font::DoNotPaintIfFontNotReady);
379 WEBCORE_EXPORT float drawBidiText(const Font&, const TextRun&, const FloatPoint&, Font::CustomFontNotReadyAction = Font::DoNotPaintIfFontNotReady, BidiStatus* = 0, int length = -1);
383 RoundOriginAndDimensions
385 FloatRect roundToDevicePixels(const FloatRect&, RoundingMode = RoundAllSides);
387 FloatRect computeLineBoundsForText(const FloatPoint&, float width, bool printing);
388 WEBCORE_EXPORT void drawLineForText(const FloatPoint&, float width, bool printing, bool doubleLines = false);
389 void drawLinesForText(const FloatPoint&, const DashArray& widths, bool printing, bool doubleLines = false);
390 enum DocumentMarkerLineStyle {
392 TextCheckingDictationPhraseWithAlternativesLineStyle,
394 DocumentMarkerSpellingLineStyle,
395 DocumentMarkerGrammarLineStyle,
396 DocumentMarkerAutocorrectionReplacementLineStyle,
397 DocumentMarkerDictationAlternativesLineStyle
399 static void updateDocumentMarkerResources();
400 void drawLineForDocumentMarker(const FloatPoint&, float width, DocumentMarkerLineStyle);
402 WEBCORE_EXPORT bool paintingDisabled() const;
403 void setPaintingDisabled(bool);
405 WEBCORE_EXPORT bool updatingControlTints() const;
406 void setUpdatingControlTints(bool);
408 WEBCORE_EXPORT void beginTransparencyLayer(float opacity);
409 WEBCORE_EXPORT void endTransparencyLayer();
410 bool isInTransparencyLayer() const;
412 bool hasShadow() const;
413 WEBCORE_EXPORT void setShadow(const FloatSize&, float blur, const Color&, ColorSpace);
414 // Legacy shadow blur radius is used for canvas, and -webkit-box-shadow.
415 // It has different treatment of radii > 8px.
416 void setLegacyShadow(const FloatSize&, float blur, const Color&, ColorSpace);
418 bool getShadow(FloatSize&, float&, Color&, ColorSpace&) const;
419 WEBCORE_EXPORT void clearShadow();
421 bool hasBlurredShadow() const;
423 bool mustUseShadowBlur() const;
426 void drawFocusRing(const Vector<IntRect>&, int width, int offset, const Color&);
427 void drawFocusRing(const Path&, int width, int offset, const Color&);
429 void drawFocusRing(const Vector<IntRect>&, int width, int offset, double timeOffset, bool& needsRedraw);
432 void setLineCap(LineCap);
433 void setLineDash(const DashArray&, float dashOffset);
434 void setLineJoin(LineJoin);
435 void setMiterLimit(float);
437 void setAlpha(float);
439 WEBCORE_EXPORT void setCompositeOperation(CompositeOperator, BlendMode = BlendModeNormal);
440 CompositeOperator compositeOperation() const;
441 BlendMode blendModeOperation() const;
443 void setDrawLuminanceMask(bool);
444 bool drawLuminanceMask() const;
446 WEBCORE_EXPORT void clip(const Path&, WindRule = RULE_EVENODD);
448 // This clip function is used only by <canvas> code. It allows
449 // implementations to handle clipping on the canvas differently since
450 // the discipline is different.
451 void canvasClip(const Path&, WindRule = RULE_EVENODD);
452 void clipOut(const Path&);
454 WEBCORE_EXPORT void scale(const FloatSize&);
455 void rotate(float angleInRadians);
456 void translate(const FloatSize& size) { translate(size.width(), size.height()); }
457 WEBCORE_EXPORT void translate(float x, float y);
459 void setURLForRect(const URL&, const IntRect&);
461 void concatCTM(const AffineTransform&);
462 void setCTM(const AffineTransform&);
464 enum IncludeDeviceScale { DefinitelyIncludeDeviceScale, PossiblyIncludeDeviceScale };
465 AffineTransform getCTM(IncludeDeviceScale includeScale = PossiblyIncludeDeviceScale) const;
467 #if ENABLE(3D_RENDERING) && USE(TEXTURE_MAPPER)
468 // This is needed when using accelerated-compositing in software mode, like in TextureMapper.
469 void concat3DTransform(const TransformationMatrix&);
470 void set3DTransform(const TransformationMatrix&);
471 TransformationMatrix get3DTransform() const;
473 // Create an image buffer compatible with this context, with suitable resolution
474 // for drawing into the buffer and then into this context.
475 std::unique_ptr<ImageBuffer> createCompatibleBuffer(const FloatSize&, bool hasAlpha = true) const;
476 bool isCompatibleWithBuffer(ImageBuffer*) const;
478 // This function applies the device scale factor to the context, making the context capable of
479 // acting as a base-level context for a HiDPI environment.
480 WEBCORE_EXPORT void applyDeviceScaleFactor(float);
481 void platformApplyDeviceScaleFactor(float);
484 HDC getWindowsContext(const IntRect&, bool supportAlphaBlend, bool mayCreateBitmap); // The passed in rect is used to create a bitmap for compositing inside transparency layers.
485 void releaseWindowsContext(HDC, const IntRect&, bool supportAlphaBlend, bool mayCreateBitmap); // The passed in HDC should be the one handed back by getWindowsContext.
488 void setBitmap(PassRefPtr<SharedBitmap>);
489 const AffineTransform& affineTransform() const;
490 AffineTransform& affineTransform();
491 void resetAffineTransform();
492 void fillRect(const FloatRect&, const Gradient*);
493 void drawText(const SimpleFontData* fontData, const GlyphBuffer& glyphBuffer, int from, int numGlyphs, const FloatPoint& point);
494 void drawFrameControl(const IntRect& rect, unsigned type, unsigned state);
495 void drawFocusRect(const IntRect& rect);
496 void paintTextField(const IntRect& rect, unsigned state);
497 void drawBitmap(SharedBitmap*, const IntRect& dstRect, const IntRect& srcRect, ColorSpace styleColorSpace, CompositeOperator compositeOp, BlendMode blendMode);
498 void drawBitmapPattern(SharedBitmap*, const FloatRect& tileRectIn, const AffineTransform& patternTransform, const FloatPoint& phase, ColorSpace styleColorSpace, CompositeOperator op, const FloatRect& destRect, const IntSize& origSourceSize);
499 void drawIcon(HICON icon, const IntRect& dstRect, UINT flags);
500 void drawRoundCorner(bool newClip, RECT clipRect, RECT rectWin, HDC dc, int width, int height);
502 GraphicsContext(HDC, bool hasAlpha = false); // FIXME: To be removed.
504 // When set to true, child windows should be rendered into this context
505 // rather than allowing them just to render to the screen. Defaults to
507 // FIXME: This is a layering violation. GraphicsContext shouldn't know
508 // what a "window" is. It would be much more appropriate for this flag
509 // to be passed as a parameter alongside the GraphicsContext, but doing
510 // that would require lots of changes in cross-platform code that we
511 // aren't sure we want to make.
512 void setShouldIncludeChildWindows(bool);
513 bool shouldIncludeChildWindows() const;
515 class WindowsBitmap {
516 WTF_MAKE_NONCOPYABLE(WindowsBitmap);
518 WindowsBitmap(HDC, const IntSize&);
521 HDC hdc() const { return m_hdc; }
522 UInt8* buffer() const { return m_pixelData.buffer(); }
523 unsigned bufferLength() const { return m_pixelData.bufferLength(); }
524 const IntSize& size() const { return m_pixelData.size(); }
525 unsigned bytesPerRow() const { return m_pixelData.bytesPerRow(); }
526 unsigned short bitsPerPixel() const { return m_pixelData.bitsPerPixel(); }
527 const DIBPixelData& windowsDIB() const { return m_pixelData; }
532 DIBPixelData m_pixelData;
535 PassOwnPtr<WindowsBitmap> createWindowsBitmap(const IntSize&);
536 // The bitmap should be non-premultiplied.
537 void drawWindowsBitmap(WindowsBitmap*, const IntPoint&);
539 #else // PLATFORM(WIN)
540 bool shouldIncludeChildWindows() const { return false; }
541 #endif // PLATFORM(WIN)
542 #endif // OS(WINDOWS)
545 GraphicsContext(cairo_t*);
549 void setGdkExposeEvent(GdkEventExpose*);
550 GdkWindow* gdkWindow() const;
551 GdkEventExpose* gdkExposeEvent() const;
554 static void adjustLineToPixelBoundaries(FloatPoint& p1, FloatPoint& p2, float strokeWidth, StrokeStyle);
557 void platformInit(PlatformGraphicsContext*, bool shouldUseContextColors = false);
558 void platformDestroy();
560 #if PLATFORM(WIN) && !USE(WINGDI)
561 void platformInit(HDC, bool hasAlpha = false);
564 void savePlatformState();
565 void restorePlatformState();
567 void setPlatformTextDrawingMode(TextDrawingModeFlags);
569 void setPlatformStrokeColor(const Color&, ColorSpace);
570 void setPlatformStrokeStyle(StrokeStyle);
571 void setPlatformStrokeThickness(float);
573 void setPlatformFillColor(const Color&, ColorSpace);
575 void setPlatformShouldAntialias(bool);
576 void setPlatformShouldSmoothFonts(bool);
578 void setPlatformShadow(const FloatSize&, float blur, const Color&, ColorSpace);
579 void clearPlatformShadow();
581 void setPlatformCompositeOperation(CompositeOperator, BlendMode = BlendModeNormal);
583 void beginPlatformTransparencyLayer(float opacity);
584 void endPlatformTransparencyLayer();
585 static bool supportsTransparencyLayers();
587 void fillEllipseAsPath(const FloatRect&);
588 void strokeEllipseAsPath(const FloatRect&);
590 void platformFillEllipse(const FloatRect&);
591 void platformStrokeEllipse(const FloatRect&);
593 void platformFillRoundedRect(const FloatRoundedRect&, const Color&, ColorSpace);
595 FloatRect computeLineBoundsAndAntialiasingModeForText(const FloatPoint&, float width, bool printing, bool& shouldAntialias, Color&);
597 GraphicsContextPlatformPrivate* m_data;
599 GraphicsContextState m_state;
600 Vector<GraphicsContextState> m_stack;
601 bool m_updatingControlTints;
602 unsigned m_transparencyCount;
605 class GraphicsContextStateSaver {
606 WTF_MAKE_FAST_ALLOCATED;
608 GraphicsContextStateSaver(GraphicsContext& context, bool saveAndRestore = true)
610 , m_saveAndRestore(saveAndRestore)
612 if (m_saveAndRestore)
616 ~GraphicsContextStateSaver()
618 if (m_saveAndRestore)
624 ASSERT(!m_saveAndRestore);
626 m_saveAndRestore = true;
631 ASSERT(m_saveAndRestore);
633 m_saveAndRestore = false;
636 GraphicsContext* context() const { return &m_context; }
639 GraphicsContext& m_context;
640 bool m_saveAndRestore;
643 } // namespace WebCore
645 #endif // GraphicsContext_h