| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2003, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. | 2 * Copyright (C) 2003, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2008-2009 Torch Mobile, Inc. | 3 * Copyright (C) 2008-2009 Torch Mobile, Inc. |
| 4 * Copyright (C) 2013 Google Inc. All rights reserved. | 4 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 5 * | 5 * |
| 6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
| 7 * modification, are permitted provided that the following conditions | 7 * modification, are permitted provided that the following conditions |
| 8 * are met: | 8 * are met: |
| 9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 #include "platform/TraceEvent.h" | 32 #include "platform/TraceEvent.h" |
| 33 #include "platform/fonts/Font.h" | 33 #include "platform/fonts/Font.h" |
| 34 #include "platform/geometry/FloatRect.h" | 34 #include "platform/geometry/FloatRect.h" |
| 35 #include "platform/graphics/DashArray.h" | 35 #include "platform/graphics/DashArray.h" |
| 36 #include "platform/graphics/DrawLooperBuilder.h" | 36 #include "platform/graphics/DrawLooperBuilder.h" |
| 37 #include "platform/graphics/ImageBufferSurface.h" | 37 #include "platform/graphics/ImageBufferSurface.h" |
| 38 #include "platform/graphics/ImageOrientation.h" | 38 #include "platform/graphics/ImageOrientation.h" |
| 39 #include "platform/graphics/GraphicsContextAnnotation.h" | 39 #include "platform/graphics/GraphicsContextAnnotation.h" |
| 40 #include "platform/graphics/GraphicsContextState.h" | 40 #include "platform/graphics/GraphicsContextState.h" |
| 41 #include "platform/graphics/skia/OpaqueRegionSkia.h" | 41 #include "platform/graphics/skia/OpaqueRegionSkia.h" |
| 42 #include "platform/graphics/skia/SkiaUtils.h" | |
| 43 #include "wtf/FastAllocBase.h" | 42 #include "wtf/FastAllocBase.h" |
| 44 #include "wtf/Forward.h" | 43 #include "wtf/Forward.h" |
| 45 #include "wtf/Noncopyable.h" | 44 #include "wtf/Noncopyable.h" |
| 46 #include "wtf/PassOwnPtr.h" | 45 #include "wtf/PassOwnPtr.h" |
| 47 | 46 |
| 48 class SkBitmap; | 47 class SkBitmap; |
| 49 class SkPaint; | 48 class SkPaint; |
| 50 class SkPath; | 49 class SkPath; |
| 51 class SkRRect; | 50 class SkRRect; |
| 52 struct SkRect; | 51 struct SkRect; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 const SkBitmap* bitmap() const; | 89 const SkBitmap* bitmap() const; |
| 91 const SkBitmap& layerBitmap(AccessMode = ReadOnly) const; | 90 const SkBitmap& layerBitmap(AccessMode = ReadOnly) const; |
| 92 | 91 |
| 93 // ---------- State management methods ----------------- | 92 // ---------- State management methods ----------------- |
| 94 void save(); | 93 void save(); |
| 95 void restore(); | 94 void restore(); |
| 96 | 95 |
| 97 void saveLayer(const SkRect* bounds, const SkPaint*, SkCanvas::SaveFlags = S
kCanvas::kARGB_ClipLayer_SaveFlag); | 96 void saveLayer(const SkRect* bounds, const SkPaint*, SkCanvas::SaveFlags = S
kCanvas::kARGB_ClipLayer_SaveFlag); |
| 98 void restoreLayer(); | 97 void restoreLayer(); |
| 99 | 98 |
| 100 float strokeThickness() const { return m_paintState->m_strokeData.thickness(
); } | 99 float strokeThickness() const { return immutableState()->strokeData().thickn
ess(); } |
| 101 void setStrokeThickness(float thickness) { mutableState()->m_strokeData.setT
hickness(thickness); } | 100 void setStrokeThickness(float thickness) { mutableState()->setStrokeThicknes
s(thickness); } |
| 102 | 101 |
| 103 StrokeStyle strokeStyle() const { return m_paintState->m_strokeData.style();
} | 102 StrokeStyle strokeStyle() const { return immutableState()->strokeData().styl
e(); } |
| 104 void setStrokeStyle(StrokeStyle style) { mutableState()->m_strokeData.setSty
le(style); } | 103 void setStrokeStyle(StrokeStyle style) { mutableState()->setStrokeStyle(styl
e); } |
| 105 | 104 |
| 106 Color strokeColor() const { return m_paintState->m_strokeData.color(); } | 105 Color strokeColor() const { return immutableState()->strokeData().color(); } |
| 107 void setStrokeColor(const Color&); | 106 void setStrokeColor(const Color& color) { mutableState()->setStrokeColor(col
or); } |
| 107 SkColor effectiveStrokeColor() const { return immutableState()->effectiveStr
okeColor(); } |
| 108 | 108 |
| 109 Pattern* strokePattern() const { return m_paintState->m_strokeData.pattern()
; } | 109 Pattern* strokePattern() const { return immutableState()->strokeData().patte
rn(); } |
| 110 void setStrokePattern(PassRefPtr<Pattern>); | 110 void setStrokePattern(PassRefPtr<Pattern>); |
| 111 | 111 |
| 112 Gradient* strokeGradient() const { return m_paintState->m_strokeData.gradien
t(); } | 112 Gradient* strokeGradient() const { return immutableState()->strokeData().gra
dient(); } |
| 113 void setStrokeGradient(PassRefPtr<Gradient>); | 113 void setStrokeGradient(PassRefPtr<Gradient>); |
| 114 | 114 |
| 115 void setLineCap(LineCap cap) { mutableState()->m_strokeData.setLineCap(cap);
} | 115 void setLineCap(LineCap cap) { mutableState()->setLineCap(cap); } |
| 116 void setLineDash(const DashArray& dashes, float dashOffset) { mutableState()
->m_strokeData.setLineDash(dashes, dashOffset); } | 116 void setLineDash(const DashArray& dashes, float dashOffset) { mutableState()
->setLineDash(dashes, dashOffset); } |
| 117 void setLineJoin(LineJoin join) { mutableState()->m_strokeData.setLineJoin(j
oin); } | 117 void setLineJoin(LineJoin join) { mutableState()->setLineJoin(join); } |
| 118 void setMiterLimit(float limit) { mutableState()->m_strokeData.setMiterLimit
(limit); } | 118 void setMiterLimit(float limit) { mutableState()->setMiterLimit(limit); } |
| 119 | 119 |
| 120 WindRule fillRule() const { return m_paintState->m_fillRule; } | 120 WindRule fillRule() const { return immutableState()->fillRule(); } |
| 121 void setFillRule(WindRule fillRule) { mutableState()->m_fillRule = fillRule;
} | 121 void setFillRule(WindRule fillRule) { mutableState()->setFillRule(fillRule);
} |
| 122 | 122 |
| 123 Color fillColor() const { return m_paintState->m_fillColor; } | 123 Color fillColor() const { return immutableState()->fillColor(); } |
| 124 void setFillColor(const Color&); | 124 void setFillColor(const Color& color) { mutableState()->setFillColor(color);
} |
| 125 SkColor effectiveFillColor() const { return m_paintState->applyAlpha(m_paint
State->m_fillColor.rgb()); } | 125 SkColor effectiveFillColor() const { return immutableState()->effectiveFillC
olor(); } |
| 126 | 126 |
| 127 void setFillPattern(PassRefPtr<Pattern>); | 127 void setFillPattern(PassRefPtr<Pattern>); |
| 128 Pattern* fillPattern() const { return m_paintState->m_fillPattern.get(); } | 128 Pattern* fillPattern() const { return immutableState()->fillPattern(); } |
| 129 | 129 |
| 130 void setFillGradient(PassRefPtr<Gradient>); | 130 void setFillGradient(PassRefPtr<Gradient>); |
| 131 Gradient* fillGradient() const { return m_paintState->m_fillGradient.get();
} | 131 Gradient* fillGradient() const { return immutableState()->fillGradient(); } |
| 132 | 132 |
| 133 SkDrawLooper* drawLooper() const { return m_paintState->m_looper.get(); } | 133 SkDrawLooper* drawLooper() const { return immutableState()->drawLooper(); } |
| 134 SkColor effectiveStrokeColor() const { return m_paintState->applyAlpha(m_pai
ntState->m_strokeData.color().rgb()); } | |
| 135 | |
| 136 int getNormalizedAlpha() const; | |
| 137 | 134 |
| 138 FloatRect getClipBounds() const; | 135 FloatRect getClipBounds() const; |
| 139 bool getTransformedClipBounds(FloatRect* bounds) const; | 136 bool getTransformedClipBounds(FloatRect* bounds) const; |
| 140 SkMatrix getTotalMatrix() const; | 137 SkMatrix getTotalMatrix() const; |
| 141 bool isPrintingDevice() const; | 138 bool isPrintingDevice() const; |
| 142 | 139 |
| 143 void setShouldAntialias(bool antialias) { mutableState()->m_shouldAntialias
= antialias; } | 140 void setShouldAntialias(bool antialias) { mutableState()->setShouldAntialias
(antialias); } |
| 144 bool shouldAntialias() const { return m_paintState->m_shouldAntialias; } | 141 bool shouldAntialias() const { return immutableState()->shouldAntialias(); } |
| 145 | 142 |
| 146 void setShouldClampToSourceRect(bool clampToSourceRect) { mutableState()->m_
shouldClampToSourceRect = clampToSourceRect; } | 143 void setShouldClampToSourceRect(bool clampToSourceRect) { mutableState()->se
tShouldClampToSourceRect(clampToSourceRect); } |
| 147 bool shouldClampToSourceRect() const { return m_paintState->m_shouldClampToS
ourceRect; } | 144 bool shouldClampToSourceRect() const { return immutableState()->shouldClampT
oSourceRect(); } |
| 148 | 145 |
| 149 void setShouldSmoothFonts(bool smoothFonts) { mutableState()->m_shouldSmooth
Fonts = smoothFonts; } | 146 void setShouldSmoothFonts(bool smoothFonts) { mutableState()->setShouldSmoot
hFonts(smoothFonts); } |
| 150 bool shouldSmoothFonts() const { return m_paintState->m_shouldSmoothFonts; } | 147 bool shouldSmoothFonts() const { return immutableState()->shouldSmoothFonts(
); } |
| 151 | 148 |
| 152 // Turn off LCD text for the paint if not supported on this context. | 149 // Turn off LCD text for the paint if not supported on this context. |
| 153 void adjustTextRenderMode(SkPaint*); | 150 void adjustTextRenderMode(SkPaint*); |
| 154 bool couldUseLCDRenderedText(); | 151 bool couldUseLCDRenderedText(); |
| 155 | 152 |
| 156 void setTextDrawingMode(TextDrawingModeFlags mode) { mutableState()->m_textD
rawingMode = mode; } | 153 void setTextDrawingMode(TextDrawingModeFlags mode) { mutableState()->setText
DrawingMode(mode); } |
| 157 TextDrawingModeFlags textDrawingMode() const { return m_paintState->m_textDr
awingMode; } | 154 TextDrawingModeFlags textDrawingMode() const { return immutableState()->text
DrawingMode(); } |
| 158 | 155 |
| 159 void setAlpha(float alpha) { mutableState()->m_alpha = alpha;} | 156 void setAlpha(float alpha) { mutableState()->setAlpha(alpha);} |
| 157 int getNormalizedAlpha() const |
| 158 { |
| 159 int alpha = immutableState()->alpha(); |
| 160 return alpha > 255 ? 255 : alpha; |
| 161 } |
| 160 | 162 |
| 161 void setImageInterpolationQuality(InterpolationQuality quality) { mutableSta
te()->m_interpolationQuality = quality; } | 163 void setImageInterpolationQuality(InterpolationQuality quality) { mutableSta
te()->setInterpolationQuality(quality); } |
| 162 InterpolationQuality imageInterpolationQuality() const { return m_paintState
->m_interpolationQuality; } | 164 InterpolationQuality imageInterpolationQuality() const { return immutableSta
te()->interpolationQuality(); } |
| 163 | 165 |
| 164 void setCompositeOperation(CompositeOperator, blink::WebBlendMode = blink::W
ebBlendModeNormal); | 166 void setCompositeOperation(CompositeOperator, blink::WebBlendMode = blink::W
ebBlendModeNormal); |
| 165 CompositeOperator compositeOperation() const { return m_paintState->m_compos
iteOperator; } | 167 CompositeOperator compositeOperation() const { return immutableState()->comp
ositeOperator(); } |
| 166 blink::WebBlendMode blendModeOperation() const { return m_paintState->m_blen
dMode; } | 168 blink::WebBlendMode blendModeOperation() const { return immutableState()->bl
endMode(); } |
| 167 | 169 |
| 168 // Change the way document markers are rendered. | 170 // Change the way document markers are rendered. |
| 169 // Any deviceScaleFactor higher than 1.5 is enough to justify setting this f
lag. | 171 // Any deviceScaleFactor higher than 1.5 is enough to justify setting this f
lag. |
| 170 void setUseHighResMarkers(bool isHighRes) { m_useHighResMarker = isHighRes;
} | 172 void setUseHighResMarkers(bool isHighRes) { m_useHighResMarker = isHighRes;
} |
| 171 | 173 |
| 172 // If true we are (most likely) rendering to a web page and the | 174 // If true we are (most likely) rendering to a web page and the |
| 173 // canvas has been prepared with an opaque background. If false, | 175 // canvas has been prepared with an opaque background. If false, |
| 174 // the canvas may have transparency (as is the case when rendering | 176 // the canvas may have transparency (as is the case when rendering |
| 175 // to a canvas object). | 177 // to a canvas object). |
| 176 void setCertainlyOpaque(bool isOpaque) { m_isCertainlyOpaque = isOpaque; } | 178 void setCertainlyOpaque(bool isOpaque) { m_isCertainlyOpaque = isOpaque; } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 204 SkColorFilter* colorFilter(); | 206 SkColorFilter* colorFilter(); |
| 205 void setColorFilter(ColorFilter); | 207 void setColorFilter(ColorFilter); |
| 206 // ---------- End state management methods ----------------- | 208 // ---------- End state management methods ----------------- |
| 207 | 209 |
| 208 // Get the contents of the image buffer | 210 // Get the contents of the image buffer |
| 209 bool readPixels(SkBitmap*, int, int, SkCanvas::Config8888 = SkCanvas::kNativ
e_Premul_Config8888); | 211 bool readPixels(SkBitmap*, int, int, SkCanvas::Config8888 = SkCanvas::kNativ
e_Premul_Config8888); |
| 210 | 212 |
| 211 // Sets up the paint for the current fill style. | 213 // Sets up the paint for the current fill style. |
| 212 void setupPaintForFilling(SkPaint*) const; | 214 void setupPaintForFilling(SkPaint*) const; |
| 213 | 215 |
| 214 // Sets up the paint for stroking. Returns a float representing the | 216 // Sets up the paint for the current stroke style. If a non-zero length is |
| 215 // effective width of the pen. If a non-zero length is provided, the | 217 // provided, the number of dashes/dots on a dashed/dotted line will be adjus
ted to |
| 216 // number of dashes/dots on a dashed/dotted line will be adjusted to | |
| 217 // start and end that length with a dash/dot. | 218 // start and end that length with a dash/dot. |
| 218 float setupPaintForStroking(SkPaint*, int length = 0) const; | 219 void setupPaintForStroking(SkPaint*, int length = 0) const; |
| 219 | 220 |
| 220 // These draw methods will do both stroking and filling. | 221 // These draw methods will do both stroking and filling. |
| 221 // FIXME: ...except drawRect(), which fills properly but always strokes | 222 // FIXME: ...except drawRect(), which fills properly but always strokes |
| 222 // using a 1-pixel stroke inset from the rect borders (of the correct | 223 // using a 1-pixel stroke inset from the rect borders (of the correct |
| 223 // stroke color). | 224 // stroke color). |
| 224 void drawRect(const IntRect&); | 225 void drawRect(const IntRect&); |
| 225 void drawLine(const IntPoint&, const IntPoint&); | 226 void drawLine(const IntPoint&, const IntPoint&); |
| 226 void drawEllipse(const IntRect&); | 227 void drawEllipse(const IntRect&); |
| 227 void drawConvexPolygon(size_t numPoints, const FloatPoint*, bool shouldAntia
lias = false); | 228 void drawConvexPolygon(size_t numPoints, const FloatPoint*, bool shouldAntia
lias = false); |
| 228 | 229 |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 value = -value; | 409 value = -value; |
| 409 isNeg = true; | 410 isNeg = true; |
| 410 } | 411 } |
| 411 if (value >= max) | 412 if (value >= max) |
| 412 value %= max; | 413 value %= max; |
| 413 if (isNeg) | 414 if (isNeg) |
| 414 value = -value; | 415 value = -value; |
| 415 return value; | 416 return value; |
| 416 } | 417 } |
| 417 | 418 |
| 418 // Sets up the common flags on a paint for antialiasing, effects, etc. | |
| 419 // This is implicitly called by setupPaintFill and setupPaintStroke, but | |
| 420 // you may wish to call it directly sometimes if you don't want that other | |
| 421 // behavior. | |
| 422 void setupPaintCommon(SkPaint*) const; | |
| 423 | |
| 424 // Helpers for drawing a focus ring (drawFocusRing) | 419 // Helpers for drawing a focus ring (drawFocusRing) |
| 425 void drawOuterPath(const SkPath&, SkPaint&, int); | 420 void drawOuterPath(const SkPath&, SkPaint&, int); |
| 426 void drawInnerPath(const SkPath&, SkPaint&, int); | 421 void drawInnerPath(const SkPath&, SkPaint&, int); |
| 427 | 422 |
| 428 // SkCanvas wrappers. | 423 // SkCanvas wrappers. |
| 429 bool isDrawingToLayer() const { return m_canvas->isDrawingToLayer(); } | 424 bool isDrawingToLayer() const { return m_canvas->isDrawingToLayer(); } |
| 430 | 425 |
| 431 void clipPath(const SkPath&, AntiAliasingMode = NotAntiAliased, SkRegion::Op
= SkRegion::kIntersect_Op); | 426 void clipPath(const SkPath&, AntiAliasingMode = NotAntiAliased, SkRegion::Op
= SkRegion::kIntersect_Op); |
| 432 void clipRRect(const SkRRect&, AntiAliasingMode = NotAntiAliased, SkRegion::
Op = SkRegion::kIntersect_Op); | 427 void clipRRect(const SkRRect&, AntiAliasingMode = NotAntiAliased, SkRegion::
Op = SkRegion::kIntersect_Op); |
| 433 | 428 |
| 434 bool concat(const SkMatrix&); | 429 bool concat(const SkMatrix&); |
| 435 | 430 |
| 436 // common code between setupPaintFor[Filling,Stroking] | 431 // common code between setupPaintFor[Filling,Stroking] |
| 437 void setupShader(SkPaint*, Gradient*, Pattern*, SkColor) const; | 432 void setupShader(SkPaint*, Gradient*, Pattern*, SkColor) const; |
| 438 | 433 |
| 439 // Apply deferred paint state saves | 434 // Apply deferred paint state saves |
| 440 void realizePaintSave() | 435 void realizePaintSave() |
| 441 { | 436 { |
| 442 if (m_paintState->m_saveCount) { | 437 if (m_paintState->saveCount()) { |
| 443 --m_paintState->m_saveCount; | 438 m_paintState->decrementSaveCount(); |
| 444 ++m_paintStateIndex; | 439 ++m_paintStateIndex; |
| 445 if (m_paintStateStack.size() == m_paintStateIndex) | 440 if (m_paintStateStack.size() == m_paintStateIndex) |
| 446 m_paintStateStack.append(GraphicsContextState::create()); | 441 m_paintStateStack.append(GraphicsContextState::create()); |
| 447 GraphicsContextState* priorPaintState = m_paintState; | 442 GraphicsContextState* priorPaintState = m_paintState; |
| 448 m_paintState = m_paintStateStack[m_paintStateIndex].get(); | 443 m_paintState = m_paintStateStack[m_paintStateIndex].get(); |
| 449 m_paintState->copy(priorPaintState); | 444 m_paintState->copy(priorPaintState); |
| 450 } | 445 } |
| 451 } | 446 } |
| 452 | 447 |
| 453 // Apply deferred canvas state saves | 448 // Apply deferred canvas state saves |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 509 // FIXME: Make this go away: crbug.com/236892 | 504 // FIXME: Make this go away: crbug.com/236892 |
| 510 bool m_updatingControlTints : 1; | 505 bool m_updatingControlTints : 1; |
| 511 bool m_accelerated : 1; | 506 bool m_accelerated : 1; |
| 512 bool m_isCertainlyOpaque : 1; | 507 bool m_isCertainlyOpaque : 1; |
| 513 bool m_printing : 1; | 508 bool m_printing : 1; |
| 514 }; | 509 }; |
| 515 | 510 |
| 516 } // namespace WebCore | 511 } // namespace WebCore |
| 517 | 512 |
| 518 #endif // GraphicsContext_h | 513 #endif // GraphicsContext_h |
| OLD | NEW |