Remove duplicate implementation of drawEllipse and some related PLATFORM(IOS) ifdefs
[WebKit-https.git] / Source / WebCore / platform / graphics / GraphicsContext.h
1 /*
2  * Copyright (C) 2003, 2006, 2007, 2008, 2009, 2013 Apple Inc. All rights reserved.
3  * Copyright (C) 2008-2009 Torch Mobile, Inc.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
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.
13  *
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.
25  */
26
27 #ifndef GraphicsContext_h
28 #define GraphicsContext_h
29
30 #include "ColorSpace.h"
31 #include "DashArray.h"
32 #include "FloatRect.h"
33 #include "Font.h"
34 #include "Gradient.h"
35 #include "Image.h"
36 #include "ImageOrientation.h"
37 #include "Path.h"
38 #include "Pattern.h"
39 #include <wtf/Noncopyable.h>
40 #include <wtf/PassOwnPtr.h>
41
42 #if USE(CG)
43 typedef struct CGContext PlatformGraphicsContext;
44 #elif USE(CAIRO)
45 namespace WebCore {
46 class PlatformContextCairo;
47 }
48 typedef WebCore::PlatformContextCairo PlatformGraphicsContext;
49 #elif USE(WINGDI)
50 typedef struct HDC__ PlatformGraphicsContext;
51 #else
52 typedef void PlatformGraphicsContext;
53 #endif
54
55 #if PLATFORM(WIN)
56 #include "DIBPixelData.h"
57 typedef struct HDC__* HDC;
58 #if !USE(CG)
59 // UInt8 is defined in CoreFoundation/CFBase.h
60 typedef unsigned char UInt8;
61 #endif
62 #endif
63
64 namespace WebCore {
65
66 #if USE(WINGDI)
67     class SharedBitmap;
68     class SimpleFontData;
69     class GlyphBuffer;
70 #endif
71
72     const int cMisspellingLineThickness = 3;
73     const int cMisspellingLinePatternWidth = 4;
74     const int cMisspellingLinePatternGapWidth = 1;
75
76     class AffineTransform;
77     class DrawingBuffer;
78     class FloatRoundedRect;
79     class Gradient;
80     class GraphicsContextPlatformPrivate;
81     class ImageBuffer;
82     class IntRect;
83     class RoundedRect;
84     class URL;
85     class GraphicsContext3D;
86     class TextRun;
87     class TransformationMatrix;
88 #if PLATFORM(IOS)
89     struct BidiStatus;
90 #endif
91
92     enum TextDrawingMode {
93         TextModeFill = 1 << 0,
94         TextModeStroke = 1 << 1,
95 #if ENABLE(LETTERPRESS)
96         TextModeLetterpress = 1 << 2,
97 #endif
98     };
99     typedef unsigned TextDrawingModeFlags;
100
101     enum StrokeStyle {
102         NoStroke,
103         SolidStroke,
104         DottedStroke,
105         DashedStroke,
106         DoubleStroke,
107         WavyStroke,
108     };
109
110     enum InterpolationQuality {
111         InterpolationDefault,
112         InterpolationNone,
113         InterpolationLow,
114         InterpolationMedium,
115         InterpolationHigh
116     };
117
118     struct GraphicsContextState {
119         GraphicsContextState()
120             : strokeThickness(0)
121             , shadowBlur(0)
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)
132 #if PLATFORM(IOS)
133             , emojiDrawingEnabled(true)
134             , shouldUseContextColors(true)
135 #endif
136             , shouldAntialias(true)
137             , shouldSmoothFonts(true)
138             , shouldSubpixelQuantizeFonts(true)
139             , paintingDisabled(false)
140             , shadowsIgnoreTransforms(false)
141 #if USE(CG)
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)
145 #endif
146             , drawLuminanceMask(false)
147         {
148         }
149
150         RefPtr<Gradient> strokeGradient;
151         RefPtr<Pattern> strokePattern;
152         
153         RefPtr<Gradient> fillGradient;
154         RefPtr<Pattern> fillPattern;
155
156         FloatSize shadowOffset;
157
158         float strokeThickness;
159         float shadowBlur;
160
161         TextDrawingModeFlags textDrawingMode;
162
163         Color strokeColor;
164         Color fillColor;
165         Color shadowColor;
166
167         StrokeStyle strokeStyle;
168         WindRule fillRule;
169
170         ColorSpace strokeColorSpace;
171         ColorSpace fillColorSpace;
172         ColorSpace shadowColorSpace;
173
174         CompositeOperator compositeOperator;
175         BlendMode blendMode;
176
177 #if PLATFORM(IOS)
178         bool emojiDrawingEnabled : 1;
179         bool shouldUseContextColors : 1;
180 #endif
181         bool shouldAntialias : 1;
182         bool shouldSmoothFonts : 1;
183         bool shouldSubpixelQuantizeFonts : 1;
184         bool paintingDisabled : 1;
185         bool shadowsIgnoreTransforms : 1;
186 #if USE(CG)
187         bool shadowsUseLegacyRadius : 1;
188 #endif
189         bool drawLuminanceMask : 1;
190     };
191
192 #if PLATFORM(IOS)
193     WEBCORE_EXPORT void setStrokeAndFillColor(PlatformGraphicsContext*, CGColorRef);
194 #endif
195
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)
202         {
203         }
204
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)
210         {
211         }
212
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)
218         {
219         }
220
221         CompositeOperator m_compositeOperator;
222         BlendMode m_blendMode;
223         ImageOrientationDescription m_orientationDescription;
224         bool m_useLowQualityScale;
225     };
226
227     class GraphicsContext {
228         WTF_MAKE_NONCOPYABLE(GraphicsContext); WTF_MAKE_FAST_ALLOCATED;
229     public:
230 #if !PLATFORM(IOS)
231         WEBCORE_EXPORT GraphicsContext(PlatformGraphicsContext*);
232 #else
233         WEBCORE_EXPORT GraphicsContext(PlatformGraphicsContext*, bool shouldUseContextColors = true);
234 #endif
235         WEBCORE_EXPORT ~GraphicsContext();
236
237         WEBCORE_EXPORT PlatformGraphicsContext* platformContext() const;
238
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);
246
247         void setStrokePattern(PassRefPtr<Pattern>);
248         Pattern* strokePattern() const;
249
250         void setStrokeGradient(PassRefPtr<Gradient>);
251         Gradient* strokeGradient() const;
252
253         WindRule fillRule() const;
254         void setFillRule(WindRule);
255         Color fillColor() const;
256         ColorSpace fillColorSpace() const;
257         WEBCORE_EXPORT void setFillColor(const Color&, ColorSpace);
258
259         void setFillPattern(PassRefPtr<Pattern>);
260         Pattern* fillPattern() const;
261
262         WEBCORE_EXPORT void setFillGradient(PassRefPtr<Gradient>);
263         Gradient* fillGradient() const;
264
265         void setShadowsIgnoreTransforms(bool);
266         bool shadowsIgnoreTransforms() const;
267
268         WEBCORE_EXPORT void setShouldAntialias(bool);
269         bool shouldAntialias() const;
270
271         WEBCORE_EXPORT void setShouldSmoothFonts(bool);
272         bool shouldSmoothFonts() const;
273
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;
278
279         const GraphicsContextState& state() const;
280
281 #if USE(CG)
282         void applyStrokePattern();
283         void applyFillPattern();
284         void drawPath(const Path&);
285
286         WEBCORE_EXPORT void drawNativeImage(PassNativeImagePtr, const FloatSize& selfSize, ColorSpace styleColorSpace, const FloatRect& destRect, const FloatRect& srcRect, CompositeOperator = CompositeSourceOver, BlendMode = BlendModeNormal, ImageOrientation = DefaultImageOrientation);
287
288         // Allow font smoothing (LCD antialiasing). Not part of the graphics state.
289         void setAllowsFontSmoothing(bool);
290         
291         WEBCORE_EXPORT void setIsCALayerContext(bool);
292         bool isCALayerContext() const;
293
294         WEBCORE_EXPORT void setIsAcceleratedContext(bool);
295 #endif
296         bool isAcceleratedContext() const;
297
298         WEBCORE_EXPORT void save();
299         WEBCORE_EXPORT void restore();
300
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
304         // stroke color).
305         void drawRect(const FloatRect&, float borderThickness = 1);
306         void drawLine(const FloatPoint&, const FloatPoint&);
307
308 #if PLATFORM(IOS)
309         void drawJoinedLines(CGPoint points[], unsigned count, bool antialias, CGLineCap = kCGLineCapButt);
310 #endif
311
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);
315
316         WEBCORE_EXPORT void fillPath(const Path&);
317         void strokePath(const Path&);
318
319         void fillEllipse(const FloatRect&);
320         void strokeEllipse(const FloatRect&);
321
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);
328
329         WEBCORE_EXPORT void clearRect(const FloatRect&);
330
331         WEBCORE_EXPORT void strokeRect(const FloatRect&, float lineWidth);
332
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());
336
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());
341
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());
345
346         WEBCORE_EXPORT void setImageInterpolationQuality(InterpolationQuality);
347         InterpolationQuality imageInterpolationQuality() const;
348
349         WEBCORE_EXPORT void clip(const IntRect&);
350         WEBCORE_EXPORT void clip(const FloatRect&);
351         void clipRoundedRect(const FloatRoundedRect&);
352
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&);
358         
359         IntRect clipBounds() const;
360
361         TextDrawingModeFlags textDrawingMode() const;
362         void setTextDrawingMode(TextDrawingModeFlags);
363
364 #if PLATFORM(IOS)
365         bool emojiDrawingEnabled();
366         WEBCORE_EXPORT void setEmojiDrawingEnabled(bool);
367 #endif
368         
369 #if !PLATFORM(IOS)
370         void drawText(const Font&, const TextRun&, const FloatPoint&, int from = 0, int to = -1);
371 #else
372         float drawText(const Font&, const TextRun&, const FloatPoint&, int from = 0, int to = -1);
373 #endif
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);
376 #if !PLATFORM(IOS)
377         void drawBidiText(const Font&, const TextRun&, const FloatPoint&, Font::CustomFontNotReadyAction = Font::DoNotPaintIfFontNotReady);
378 #else
379         WEBCORE_EXPORT float drawBidiText(const Font&, const TextRun&, const FloatPoint&, Font::CustomFontNotReadyAction = Font::DoNotPaintIfFontNotReady, BidiStatus* = 0, int length = -1);
380 #endif
381         enum RoundingMode {
382             RoundAllSides,
383             RoundOriginAndDimensions
384         };
385         FloatRect roundToDevicePixels(const FloatRect&, RoundingMode = RoundAllSides);
386
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 {
391 #if PLATFORM(IOS)
392             TextCheckingDictationPhraseWithAlternativesLineStyle,
393 #endif
394             DocumentMarkerSpellingLineStyle,
395             DocumentMarkerGrammarLineStyle,
396             DocumentMarkerAutocorrectionReplacementLineStyle,
397             DocumentMarkerDictationAlternativesLineStyle
398         };
399         static void updateDocumentMarkerResources();
400         void drawLineForDocumentMarker(const FloatPoint&, float width, DocumentMarkerLineStyle);
401
402         WEBCORE_EXPORT bool paintingDisabled() const;
403         void setPaintingDisabled(bool);
404
405         WEBCORE_EXPORT bool updatingControlTints() const;
406         void setUpdatingControlTints(bool);
407
408         WEBCORE_EXPORT void beginTransparencyLayer(float opacity);
409         WEBCORE_EXPORT void endTransparencyLayer();
410         bool isInTransparencyLayer() const;
411
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);
417
418         bool getShadow(FloatSize&, float&, Color&, ColorSpace&) const;
419         WEBCORE_EXPORT void clearShadow();
420
421         bool hasBlurredShadow() const;
422 #if USE(CAIRO)
423         bool mustUseShadowBlur() const;
424 #endif
425
426         void drawFocusRing(const Vector<IntRect>&, int width, int offset, const Color&);
427         void drawFocusRing(const Path&, int width, int offset, const Color&);
428 #if PLATFORM(MAC)
429         void drawFocusRing(const Vector<IntRect>&, int width, int offset, double timeOffset, bool& needsRedraw);
430 #endif
431
432         void setLineCap(LineCap);
433         void setLineDash(const DashArray&, float dashOffset);
434         void setLineJoin(LineJoin);
435         void setMiterLimit(float);
436
437         void setAlpha(float);
438
439         WEBCORE_EXPORT void setCompositeOperation(CompositeOperator, BlendMode = BlendModeNormal);
440         CompositeOperator compositeOperation() const;
441         BlendMode blendModeOperation() const;
442
443         void setDrawLuminanceMask(bool);
444         bool drawLuminanceMask() const;
445
446         WEBCORE_EXPORT void clip(const Path&, WindRule = RULE_EVENODD);
447
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&);
453
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);
458
459         void setURLForRect(const URL&, const IntRect&);
460
461         void concatCTM(const AffineTransform&);
462         void setCTM(const AffineTransform&);
463
464         enum IncludeDeviceScale { DefinitelyIncludeDeviceScale, PossiblyIncludeDeviceScale };
465         AffineTransform getCTM(IncludeDeviceScale includeScale = PossiblyIncludeDeviceScale) const;
466
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;
472 #endif
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;
477
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);
482
483 #if OS(WINDOWS)
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.
486 #if PLATFORM(WIN)
487 #if USE(WINGDI)
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);
501 #else
502         GraphicsContext(HDC, bool hasAlpha = false); // FIXME: To be removed.
503
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
506         // false.
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;
514
515         class WindowsBitmap {
516             WTF_MAKE_NONCOPYABLE(WindowsBitmap);
517         public:
518             WindowsBitmap(HDC, const IntSize&);
519             ~WindowsBitmap();
520
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; }
528
529         private:
530             HDC m_hdc;
531             HBITMAP m_bitmap;
532             DIBPixelData m_pixelData;
533         };
534
535         PassOwnPtr<WindowsBitmap> createWindowsBitmap(const IntSize&);
536         // The bitmap should be non-premultiplied.
537         void drawWindowsBitmap(WindowsBitmap*, const IntPoint&);
538 #endif
539 #else // PLATFORM(WIN)
540         bool shouldIncludeChildWindows() const { return false; }
541 #endif // PLATFORM(WIN)
542 #endif // OS(WINDOWS)
543
544 #if USE(CAIRO)
545         GraphicsContext(cairo_t*);
546 #endif
547
548 #if PLATFORM(GTK)
549         void setGdkExposeEvent(GdkEventExpose*);
550         GdkWindow* gdkWindow() const;
551         GdkEventExpose* gdkExposeEvent() const;
552 #endif
553
554         static void adjustLineToPixelBoundaries(FloatPoint& p1, FloatPoint& p2, float strokeWidth, StrokeStyle);
555
556     private:
557         void platformInit(PlatformGraphicsContext*, bool shouldUseContextColors = false);
558         void platformDestroy();
559
560 #if PLATFORM(WIN) && !USE(WINGDI)
561         void platformInit(HDC, bool hasAlpha = false);
562 #endif
563
564         void savePlatformState();
565         void restorePlatformState();
566
567         void setPlatformTextDrawingMode(TextDrawingModeFlags);
568
569         void setPlatformStrokeColor(const Color&, ColorSpace);
570         void setPlatformStrokeStyle(StrokeStyle);
571         void setPlatformStrokeThickness(float);
572
573         void setPlatformFillColor(const Color&, ColorSpace);
574
575         void setPlatformShouldAntialias(bool);
576         void setPlatformShouldSmoothFonts(bool);
577
578         void setPlatformShadow(const FloatSize&, float blur, const Color&, ColorSpace);
579         void clearPlatformShadow();
580
581         void setPlatformCompositeOperation(CompositeOperator, BlendMode = BlendModeNormal);
582
583         void beginPlatformTransparencyLayer(float opacity);
584         void endPlatformTransparencyLayer();
585         static bool supportsTransparencyLayers();
586
587         void fillEllipseAsPath(const FloatRect&);
588         void strokeEllipseAsPath(const FloatRect&);
589
590         void platformFillEllipse(const FloatRect&);
591         void platformStrokeEllipse(const FloatRect&);
592
593         void platformFillRoundedRect(const FloatRoundedRect&, const Color&, ColorSpace);
594
595         FloatRect computeLineBoundsAndAntialiasingModeForText(const FloatPoint&, float width, bool printing, bool& shouldAntialias, Color&);
596
597         GraphicsContextPlatformPrivate* m_data;
598
599         GraphicsContextState m_state;
600         Vector<GraphicsContextState> m_stack;
601         bool m_updatingControlTints;
602         unsigned m_transparencyCount;
603     };
604
605     class GraphicsContextStateSaver {
606         WTF_MAKE_FAST_ALLOCATED;
607     public:
608         GraphicsContextStateSaver(GraphicsContext& context, bool saveAndRestore = true)
609         : m_context(context)
610         , m_saveAndRestore(saveAndRestore)
611         {
612             if (m_saveAndRestore)
613                 m_context.save();
614         }
615         
616         ~GraphicsContextStateSaver()
617         {
618             if (m_saveAndRestore)
619                 m_context.restore();
620         }
621         
622         void save()
623         {
624             ASSERT(!m_saveAndRestore);
625             m_context.save();
626             m_saveAndRestore = true;
627         }
628
629         void restore()
630         {
631             ASSERT(m_saveAndRestore);
632             m_context.restore();
633             m_saveAndRestore = false;
634         }
635         
636         GraphicsContext* context() const { return &m_context; }
637
638     private:
639         GraphicsContext& m_context;
640         bool m_saveAndRestore;
641     };
642
643 } // namespace WebCore
644
645 #endif // GraphicsContext_h
646