Upstream version 11.40.277.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / platform / graphics / GraphicsContext.h
1 /*
2  * Copyright (C) 2003, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
3  * Copyright (C) 2008-2009 Torch Mobile, Inc.
4  * Copyright (C) 2013 Google Inc. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
16  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
19  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
23  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27
28 #ifndef GraphicsContext_h
29 #define GraphicsContext_h
30
31 #include "platform/PlatformExport.h"
32 #include "platform/fonts/Font.h"
33 #include "platform/geometry/FloatRect.h"
34 #include "platform/graphics/DashArray.h"
35 #include "platform/graphics/DrawLooperBuilder.h"
36 #include "platform/graphics/ImageBufferSurface.h"
37 #include "platform/graphics/ImageFilter.h"
38 #include "platform/graphics/ImageOrientation.h"
39 #include "platform/graphics/GraphicsContextAnnotation.h"
40 #include "platform/graphics/GraphicsContextState.h"
41 #include "platform/graphics/RegionTracker.h"
42 #include "platform/graphics/skia/SkiaUtils.h"
43 #include "wtf/FastAllocBase.h"
44 #include "wtf/Forward.h"
45 #include "wtf/Noncopyable.h"
46 #include "wtf/PassOwnPtr.h"
47
48 class SkBitmap;
49 class SkPaint;
50 class SkPath;
51 class SkRRect;
52 class SkTextBlob;
53 struct SkRect;
54
55 namespace blink {
56
57 class DisplayList;
58 class ImageBuffer;
59 class KURL;
60
61 class PLATFORM_EXPORT GraphicsContext {
62     WTF_MAKE_NONCOPYABLE(GraphicsContext); WTF_MAKE_FAST_ALLOCATED;
63 public:
64     enum AntiAliasingMode {
65         NotAntiAliased,
66         AntiAliased
67     };
68     enum AccessMode {
69         ReadOnly,
70         ReadWrite
71     };
72
73     enum DisabledMode {
74         NothingDisabled = 0, // Run as normal.
75         FullyDisabled = 1 // Do absolutely minimal work to remove the cost of the context from performance tests.
76     };
77
78     // A 0 canvas is allowed, but in such cases the context must only have canvas
79     // related commands called when within a beginRecording/endRecording block.
80     // Furthermore, save/restore calls must be balanced any time the canvas is 0.
81     explicit GraphicsContext(SkCanvas*, DisabledMode = NothingDisabled);
82
83     ~GraphicsContext();
84
85     SkCanvas* canvas() { return m_canvas; }
86     const SkCanvas* canvas() const { return m_canvas; }
87
88     void resetCanvas(SkCanvas*);
89
90     bool contextDisabled() const { return m_disabledState; }
91
92     // ---------- State management methods -----------------
93     void save();
94     void restore();
95
96 #if ENABLE(ASSERT)
97     unsigned saveCount() const;
98     void disableDestructionChecks() { m_disableDestructionChecks = true; }
99 #endif
100
101     bool hasStroke() const { return strokeStyle() != NoStroke && strokeThickness() > 0; }
102
103     float strokeThickness() const { return immutableState()->strokeData().thickness(); }
104     void setStrokeThickness(float thickness) { mutableState()->setStrokeThickness(thickness); }
105
106     StrokeStyle strokeStyle() const { return immutableState()->strokeData().style(); }
107     void setStrokeStyle(StrokeStyle style) { mutableState()->setStrokeStyle(style); }
108
109     Color strokeColor() const { return immutableState()->strokeColor(); }
110     void setStrokeColor(const Color& color) { mutableState()->setStrokeColor(color); }
111     SkColor effectiveStrokeColor() const { return immutableState()->effectiveStrokeColor(); }
112
113     Pattern* strokePattern() const { return immutableState()->strokePattern(); }
114     void setStrokePattern(PassRefPtr<Pattern>);
115
116     Gradient* strokeGradient() const { return immutableState()->strokeGradient(); }
117     void setStrokeGradient(PassRefPtr<Gradient>);
118
119     void setLineCap(LineCap cap) { mutableState()->setLineCap(cap); }
120     void setLineDash(const DashArray& dashes, float dashOffset) { mutableState()->setLineDash(dashes, dashOffset); }
121     void setLineJoin(LineJoin join) { mutableState()->setLineJoin(join); }
122     void setMiterLimit(float limit) { mutableState()->setMiterLimit(limit); }
123
124     WindRule fillRule() const { return immutableState()->fillRule(); }
125     void setFillRule(WindRule fillRule) { mutableState()->setFillRule(fillRule); }
126
127     Color fillColor() const { return immutableState()->fillColor(); }
128     void setFillColor(const Color& color) { mutableState()->setFillColor(color); }
129     SkColor effectiveFillColor() const { return immutableState()->effectiveFillColor(); }
130
131     void setFillPattern(PassRefPtr<Pattern>);
132     Pattern* fillPattern() const { return immutableState()->fillPattern(); }
133
134     void setFillGradient(PassRefPtr<Gradient>);
135     Gradient* fillGradient() const { return immutableState()->fillGradient(); }
136
137     SkDrawLooper* drawLooper() const { return immutableState()->drawLooper(); }
138
139     bool getTransformedClipBounds(FloatRect* bounds) const;
140     SkMatrix getTotalMatrix() const;
141
142     void setShouldAntialias(bool antialias) { mutableState()->setShouldAntialias(antialias); }
143     bool shouldAntialias() const { return immutableState()->shouldAntialias(); }
144
145     // Disable the anti-aliasing optimization for scales/multiple-of-90-degrees
146     // rotations of thin ("hairline") images.
147     // Note: This will only be reliable when the device pixel scale/ratio is
148     // fixed (e.g. when drawing to context backed by an ImageBuffer).
149     void disableAntialiasingOptimizationForHairlineImages() { ASSERT(!isRecording()); m_antialiasHairlineImages = true; }
150     bool shouldAntialiasHairlineImages() const { return m_antialiasHairlineImages; }
151
152     void setShouldClampToSourceRect(bool clampToSourceRect) { mutableState()->setShouldClampToSourceRect(clampToSourceRect); }
153     bool shouldClampToSourceRect() const { return immutableState()->shouldClampToSourceRect(); }
154
155     // FIXME: the setter is only used once, at construction time; convert to a constructor param,
156     // and possibly consolidate with other flags (paintDisabled, isPrinting, ...)
157     void setShouldSmoothFonts(bool smoothFonts) { m_shouldSmoothFonts = smoothFonts; }
158     bool shouldSmoothFonts() const { return m_shouldSmoothFonts; }
159
160     // Turn off LCD text for the paint if not supported on this context.
161     void adjustTextRenderMode(SkPaint*) const;
162     bool couldUseLCDRenderedText() const;
163
164     void setTextDrawingMode(TextDrawingModeFlags mode) { mutableState()->setTextDrawingMode(mode); }
165     TextDrawingModeFlags textDrawingMode() const { return immutableState()->textDrawingMode(); }
166
167     void setAlphaAsFloat(float alpha) { mutableState()->setAlphaAsFloat(alpha);}
168     int getNormalizedAlpha() const
169     {
170         int alpha = immutableState()->alpha();
171         return alpha > 255 ? 255 : alpha;
172     }
173
174     void setImageInterpolationQuality(InterpolationQuality quality) { mutableState()->setInterpolationQuality(quality); }
175     InterpolationQuality imageInterpolationQuality() const { return immutableState()->interpolationQuality(); }
176
177     void setCompositeOperation(CompositeOperator, WebBlendMode = WebBlendModeNormal);
178     CompositeOperator compositeOperation() const { return immutableState()->compositeOperator(); }
179     WebBlendMode blendModeOperation() const { return immutableState()->blendMode(); }
180
181     // Speicy the device scale factor which may change the way document markers
182     // and fonts are rendered.
183     void setDeviceScaleFactor(float factor) { m_deviceScaleFactor = factor; }
184     float deviceScaleFactor() const { return m_deviceScaleFactor; }
185
186     // If true we are (most likely) rendering to a web page and the
187     // canvas has been prepared with an opaque background. If false,
188     // the canvas may have transparency (as is the case when rendering
189     // to a canvas object).
190     void setCertainlyOpaque(bool isOpaque) { m_isCertainlyOpaque = isOpaque; }
191     bool isCertainlyOpaque() const { return m_isCertainlyOpaque; }
192
193     // Returns if the context is a printing context instead of a display
194     // context. Bitmap shouldn't be resampled when printing to keep the best
195     // possible quality.
196     bool printing() const { return m_printing; }
197     void setPrinting(bool printing) { m_printing = printing; }
198
199     bool isAccelerated() const { return m_accelerated; }
200     void setAccelerated(bool accelerated) { m_accelerated = accelerated; }
201
202     // The opaque region is empty until tracking is turned on.
203     // It is never clerared by the context.
204     enum RegionTrackingMode {
205         RegionTrackingDisabled = 0,
206         RegionTrackingOpaque,
207         RegionTrackingOverwrite
208     };
209     void setRegionTrackingMode(RegionTrackingMode);
210     bool regionTrackingEnabled() { return m_regionTrackingMode != RegionTrackingDisabled; }
211     const RegionTracker& opaqueRegion() const { return m_trackedRegion; }
212
213     // The text region is empty until tracking is turned on.
214     // It is never clerared by the context.
215     void setTrackTextRegion(bool track) { m_trackTextRegion = track; }
216     const SkRect& textRegion() const { return m_textRegion; }
217
218     AnnotationModeFlags annotationMode() const { return m_annotationMode; }
219     void setAnnotationMode(const AnnotationModeFlags mode) { m_annotationMode = mode; }
220
221     SkColorFilter* colorFilter() const;
222     void setColorFilter(ColorFilter);
223     // ---------- End state management methods -----------------
224
225     // Get the contents of the image buffer
226     bool readPixels(const SkImageInfo&, void* pixels, size_t rowBytes, int x, int y);
227
228     // Get the current fill style.
229     const SkPaint& fillPaint() const { return immutableState()->fillPaint(); }
230
231     // Get the current stroke style.
232     const SkPaint& strokePaint() const { return immutableState()->strokePaint(); }
233
234     // These draw methods will do both stroking and filling.
235     // FIXME: ...except drawRect(), which fills properly but always strokes
236     // using a 1-pixel stroke inset from the rect borders (of the correct
237     // stroke color).
238     void drawRect(const IntRect&);
239     void drawLine(const IntPoint&, const IntPoint&);
240
241     void fillPolygon(size_t numPoints, const FloatPoint*, const Color&, bool shouldAntialias);
242
243     void fillPath(const Path&);
244     void strokePath(const Path&);
245
246     void fillEllipse(const FloatRect&);
247     void strokeEllipse(const FloatRect&);
248
249     void fillRect(const FloatRect&);
250     void fillRect(const FloatRect&, const Color&);
251     void fillRect(const FloatRect&, const Color&, CompositeOperator);
252     void fillRoundedRect(const IntRect&, const IntSize& topLeft, const IntSize& topRight, const IntSize& bottomLeft, const IntSize& bottomRight, const Color&);
253     void fillRoundedRect(const RoundedRect&, const Color&);
254
255     void clearRect(const FloatRect&);
256
257     void strokeRect(const FloatRect&);
258     void strokeRect(const FloatRect&, float lineWidth);
259
260     void fillBetweenRoundedRects(const IntRect&, const IntSize& outerTopLeft, const IntSize& outerTopRight, const IntSize& outerBottomLeft, const IntSize& outerBottomRight,
261         const IntRect&, const IntSize& innerTopLeft, const IntSize& innerTopRight, const IntSize& innerBottomLeft, const IntSize& innerBottomRight, const Color&);
262     void fillBetweenRoundedRects(const RoundedRect&, const RoundedRect&, const Color&);
263
264     void drawDisplayList(DisplayList*);
265     void drawPicture(SkPicture*, const FloatPoint& location);
266     void drawPicture(SkPicture*, const FloatRect& dest, const FloatRect& src, CompositeOperator, WebBlendMode);
267
268     void drawImage(Image*, const IntPoint&, CompositeOperator = CompositeSourceOver, RespectImageOrientationEnum = DoNotRespectImageOrientation);
269     void drawImage(Image*, const IntRect&, CompositeOperator = CompositeSourceOver, RespectImageOrientationEnum = DoNotRespectImageOrientation);
270     void drawImage(Image*, const FloatRect& destRect);
271     void drawImage(Image*, const FloatRect& destRect, const FloatRect& srcRect, CompositeOperator = CompositeSourceOver, RespectImageOrientationEnum = DoNotRespectImageOrientation);
272     void drawImage(Image*, const FloatRect& destRect, const FloatRect& srcRect, CompositeOperator, WebBlendMode, RespectImageOrientationEnum = DoNotRespectImageOrientation);
273
274     void drawTiledImage(Image*, const IntRect& destRect, const IntPoint& srcPoint, const IntSize& tileSize,
275         CompositeOperator = CompositeSourceOver, WebBlendMode = WebBlendModeNormal, const IntSize& repeatSpacing = IntSize());
276     void drawTiledImage(Image*, const IntRect& destRect, const IntRect& srcRect,
277         const FloatSize& tileScaleFactor, Image::TileRule hRule = Image::StretchTile, Image::TileRule vRule = Image::StretchTile,
278         CompositeOperator = CompositeSourceOver);
279
280     void drawImageBuffer(ImageBuffer*, const FloatRect& destRect, const FloatRect* srcRect = 0, CompositeOperator = CompositeSourceOver, WebBlendMode = WebBlendModeNormal);
281
282     // These methods write to the canvas and modify the opaque region, if tracked.
283     // Also drawLine(const IntPoint& point1, const IntPoint& point2) and fillRoundedRect
284     void writePixels(const SkImageInfo&, const void* pixels, size_t rowBytes, int x, int y);
285     void drawBitmap(const SkBitmap&, SkScalar, SkScalar, const SkPaint* = 0);
286     void drawBitmapRect(const SkBitmap&, const SkRect*, const SkRect&, const SkPaint* = 0);
287     void drawOval(const SkRect&, const SkPaint&);
288     void drawPath(const SkPath&, const SkPaint&);
289     // After drawing directly to the context's canvas, use this function to notify the context so
290     // it can track the opaque region.
291     // FIXME: this is still needed only because ImageSkia::paintSkBitmap() may need to notify for a
292     //        smaller rect than the one drawn to, due to its clipping logic.
293     void didDrawRect(const SkRect&, const SkPaint&, const SkBitmap* = 0);
294     void drawRect(const SkRect&, const SkPaint&);
295     void drawPosText(const void* text, size_t byteLength, const SkPoint pos[], const SkRect& textRect, const SkPaint&);
296     void drawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[], SkScalar constY, const SkRect& textRect, const SkPaint&);
297     void drawTextBlob(const SkTextBlob*, const SkPoint& origin, const SkPaint&);
298
299     void clip(const IntRect& rect) { clipRect(rect); }
300     void clip(const FloatRect& rect) { clipRect(rect); }
301     void clipRoundedRect(const RoundedRect&, SkRegion::Op = SkRegion::kIntersect_Op);
302     void clipOut(const IntRect& rect) { clipRect(rect, NotAntiAliased, SkRegion::kDifference_Op); }
303     void clipOut(const Path&);
304     void clipOutRoundedRect(const RoundedRect&);
305     void clipPath(const Path&, WindRule = RULE_EVENODD);
306     void clipPolygon(size_t numPoints, const FloatPoint*, bool antialias);
307     void clipRect(const SkRect&, AntiAliasingMode = NotAntiAliased, SkRegion::Op = SkRegion::kIntersect_Op);
308     // This clip function is used only by <canvas> code. It allows
309     // implementations to handle clipping on the canvas differently since
310     // the discipline is different.
311     void canvasClip(const Path&, WindRule = RULE_EVENODD, AntiAliasingMode = NotAntiAliased);
312
313     void drawText(const Font&, const TextRunPaintInfo&, const FloatPoint&);
314     void drawEmphasisMarks(const Font&, const TextRunPaintInfo&, const AtomicString& mark, const FloatPoint&);
315     void drawBidiText(const Font&, const TextRunPaintInfo&, const FloatPoint&, Font::CustomFontNotReadyAction = Font::DoNotPaintIfFontNotReady);
316     void drawHighlightForText(const Font&, const TextRun&, const FloatPoint&, int h, const Color& backgroundColor, int from = 0, int to = -1);
317
318     void drawLineForText(const FloatPoint&, float width, bool printing);
319     enum DocumentMarkerLineStyle {
320         DocumentMarkerSpellingLineStyle,
321         DocumentMarkerGrammarLineStyle
322     };
323     void drawLineForDocumentMarker(const FloatPoint&, float width, DocumentMarkerLineStyle);
324
325     // beginLayer()/endLayer() behaves like save()/restore() for only CTM and clip states.
326     void beginTransparencyLayer(float opacity, const FloatRect* = 0);
327     // Apply CompositeOperator when the layer is composited on the backdrop (i.e. endLayer()).
328     // Don't change the current CompositeOperator state.
329     void beginLayer(float opacity, CompositeOperator, const FloatRect* = 0, ColorFilter = ColorFilterNone, ImageFilter* = 0);
330     void endLayer();
331
332     void beginCull(const FloatRect&);
333     void endCull();
334
335     // Instead of being dispatched to the active canvas, draw commands following beginRecording()
336     // are stored in a display list that can be replayed at a later time. Pass in the bounding
337     // rectangle for the content in the list.
338     void beginRecording(const FloatRect&, uint32_t = 0);
339     PassRefPtr<DisplayList> endRecording();
340
341     bool hasShadow() const;
342     void setShadow(const FloatSize& offset, float blur, const Color&,
343         DrawLooperBuilder::ShadowTransformMode = DrawLooperBuilder::ShadowRespectsTransforms,
344         DrawLooperBuilder::ShadowAlphaMode = DrawLooperBuilder::ShadowRespectsAlpha, ShadowMode = DrawShadowAndForeground);
345     void clearShadow() { clearDrawLooper(); clearDropShadowImageFilter(); }
346
347     // It is assumed that this draw looper is used only for shadows
348     // (i.e. a draw looper is set if and only if there is a shadow).
349     // The builder passed into this method will be destroyed.
350     void setDrawLooper(PassOwnPtr<DrawLooperBuilder>);
351     void clearDrawLooper();
352
353     void drawFocusRing(const Vector<IntRect>&, int width, int offset, const Color&);
354     void drawFocusRing(const Path&, int width, int offset, const Color&);
355
356     enum Edge {
357         NoEdge = 0,
358         TopEdge = 1 << 1,
359         RightEdge = 1 << 2,
360         BottomEdge = 1 << 3,
361         LeftEdge = 1 << 4
362     };
363     typedef unsigned Edges;
364     void drawInnerShadow(const RoundedRect&, const Color& shadowColor, const IntSize shadowOffset, int shadowBlur, int shadowSpread, Edges clippedEdges = NoEdge);
365
366     // ---------- Transformation methods -----------------
367     // Note that the getCTM method returns only the current transform from Blink's perspective,
368     // which is not the final transform used to place content on screen. It cannot be relied upon
369     // for testing where a point will appear on screen or how large it will be.
370     AffineTransform getCTM() const;
371     void concatCTM(const AffineTransform& affine) { concat(affineTransformToSkMatrix(affine)); }
372     void setCTM(const AffineTransform& affine) { setMatrix(affineTransformToSkMatrix(affine)); }
373     void setMatrix(const SkMatrix&);
374
375     void scale(float x, float y);
376     void rotate(float angleInRadians);
377     void translate(float x, float y);
378
379     // This function applies the device scale factor to the context, making the context capable of
380     // acting as a base-level context for a HiDPI environment.
381     void applyDeviceScaleFactor(float deviceScaleFactor) { scale(deviceScaleFactor, deviceScaleFactor); }
382     // ---------- End transformation methods -----------------
383
384     // URL drawing
385     void setURLForRect(const KURL&, const IntRect&);
386     void setURLFragmentForRect(const String& name, const IntRect&);
387     void addURLTargetAtPoint(const String& name, const IntPoint&);
388
389     // Create an image buffer compatible with this context, with suitable resolution
390     // for drawing into the buffer and then into this context.
391     PassOwnPtr<ImageBuffer> createRasterBuffer(const IntSize&, OpacityMode = NonOpaque) const;
392
393     static void adjustLineToPixelBoundaries(FloatPoint& p1, FloatPoint& p2, float strokeWidth, StrokeStyle);
394
395     void beginAnnotation(const AnnotationList&);
396     void endAnnotation();
397
398     void preparePaintForDrawRectToRect(
399         SkPaint*,
400         const SkRect& srcRect,
401         const SkRect& destRect,
402         CompositeOperator,
403         WebBlendMode,
404         bool isBitmapWithAlpha,
405         bool isLazyDecoded = false,
406         bool isDataComplete = true) const;
407
408     static int focusRingOutsetExtent(int offset, int width)
409     {
410         return focusRingOutset(offset) + (focusRingWidth(width) + 1) / 2;
411     }
412
413 private:
414     const GraphicsContextState* immutableState() const { return m_paintState; }
415
416     GraphicsContextState* mutableState()
417     {
418         realizePaintSave();
419         return m_paintState;
420     }
421
422     static void setPathFromPoints(SkPath*, size_t, const FloatPoint*);
423     static void setRadii(SkVector*, IntSize, IntSize, IntSize, IntSize);
424
425     static PassRefPtr<SkColorFilter> WebCoreColorFilterToSkiaColorFilter(ColorFilter);
426
427 #if OS(MACOSX)
428     static inline int focusRingOutset(int offset) { return offset + 2; }
429     static inline int focusRingWidth(int width) { return width; }
430 #else
431     static inline int focusRingOutset(int offset) { return 0; }
432     static inline int focusRingWidth(int width) { return 1; }
433     static SkPMColor lineColors(int);
434     static SkPMColor antiColors1(int);
435     static SkPMColor antiColors2(int);
436     static void draw1xMarker(SkBitmap*, int);
437     static void draw2xMarker(SkBitmap*, int);
438 #endif
439
440     void saveLayer(const SkRect* bounds, const SkPaint*);
441     void restoreLayer();
442
443     // Helpers for drawing a focus ring (drawFocusRing)
444     float prepareFocusRingPaint(SkPaint&, const Color&, int width) const;
445     void drawFocusRingPath(const SkPath&, const Color&, int width);
446     void drawFocusRingRect(const SkRect&, const Color&, int width);
447
448     // SkCanvas wrappers.
449     void clipPath(const SkPath&, AntiAliasingMode = NotAntiAliased, SkRegion::Op = SkRegion::kIntersect_Op);
450     void clipRRect(const SkRRect&, AntiAliasingMode = NotAntiAliased, SkRegion::Op = SkRegion::kIntersect_Op);
451     void concat(const SkMatrix&);
452     void drawRRect(const SkRRect&, const SkPaint&);
453
454     void setDropShadowImageFilter(PassRefPtr<SkImageFilter>);
455     void clearDropShadowImageFilter();
456     SkImageFilter* dropShadowImageFilter() const { return immutableState()->dropShadowImageFilter(); }
457
458     // Apply deferred paint state saves
459     void realizePaintSave()
460     {
461         if (contextDisabled())
462             return;
463
464         if (m_paintState->saveCount()) {
465             m_paintState->decrementSaveCount();
466             ++m_paintStateIndex;
467             if (m_paintStateStack.size() == m_paintStateIndex) {
468                 m_paintStateStack.append(GraphicsContextState::createAndCopy(*m_paintState));
469                 m_paintState = m_paintStateStack[m_paintStateIndex].get();
470             } else {
471                 GraphicsContextState* priorPaintState = m_paintState;
472                 m_paintState = m_paintStateStack[m_paintStateIndex].get();
473                 m_paintState->copy(*priorPaintState);
474             }
475         }
476     }
477
478     void didDrawTextInRect(const SkRect& textRect);
479
480     void fillRectWithRoundedHole(const IntRect&, const RoundedRect& roundedHoleRect, const Color&);
481
482     bool isRecording() const;
483
484     // null indicates painting is contextDisabled. Never delete this object.
485     SkCanvas* m_canvas;
486
487     // Paint states stack. Enables local drawing state change with save()/restore() calls.
488     // This state controls the appearance of drawn content.
489     // We do not delete from this stack to avoid memory churn.
490     Vector<OwnPtr<GraphicsContextState> > m_paintStateStack;
491     // Current index on the stack. May not be the last thing on the stack.
492     unsigned m_paintStateIndex;
493     // Raw pointer to the current state.
494     GraphicsContextState* m_paintState;
495
496     AnnotationModeFlags m_annotationMode;
497
498     struct RecordingState;
499     Vector<RecordingState> m_recordingStateStack;
500
501 #if ENABLE(ASSERT)
502     unsigned m_annotationCount;
503     unsigned m_layerCount;
504     bool m_disableDestructionChecks;
505 #endif
506     // Tracks the region painted opaque via the GraphicsContext.
507     RegionTracker m_trackedRegion;
508
509     // Tracks the region where text is painted via the GraphicsContext.
510     SkRect m_textRegion;
511
512     unsigned m_disabledState;
513
514     float m_deviceScaleFactor;
515
516     // Activation for the above region tracking features
517     unsigned m_regionTrackingMode : 2;
518     unsigned m_trackTextRegion : 1;
519
520     unsigned m_accelerated : 1;
521     unsigned m_isCertainlyOpaque : 1;
522     unsigned m_printing : 1;
523     unsigned m_antialiasHairlineImages : 1;
524     unsigned m_shouldSmoothFonts : 1;
525 };
526
527 } // namespace blink
528
529 #endif // GraphicsContext_h