| 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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 #endif | 102 #endif |
| 103 | 103 |
| 104 float strokeThickness() const { return immutableState()->strokeData().thickn
ess(); } | 104 float strokeThickness() const { return immutableState()->strokeData().thickn
ess(); } |
| 105 void setStrokeThickness(float thickness) { mutableState()->setStrokeThicknes
s(thickness); } | 105 void setStrokeThickness(float thickness) { mutableState()->setStrokeThicknes
s(thickness); } |
| 106 | 106 |
| 107 StrokeStyle strokeStyle() const { return immutableState()->strokeData().styl
e(); } | 107 StrokeStyle strokeStyle() const { return immutableState()->strokeData().styl
e(); } |
| 108 void setStrokeStyle(StrokeStyle style) { mutableState()->setStrokeStyle(styl
e); } | 108 void setStrokeStyle(StrokeStyle style) { mutableState()->setStrokeStyle(styl
e); } |
| 109 | 109 |
| 110 Color strokeColor() const { return immutableState()->strokeColor(); } | 110 Color strokeColor() const { return immutableState()->strokeColor(); } |
| 111 void setStrokeColor(const Color& color) { mutableState()->setStrokeColor(col
or); } | 111 void setStrokeColor(const Color& color) { mutableState()->setStrokeColor(col
or); } |
| 112 SkColor effectiveStrokeColor() const { return immutableState()->effectiveStr
okeColor(); } | |
| 113 | 112 |
| 114 Pattern* strokePattern() const { return immutableState()->strokePattern(); } | 113 Pattern* strokePattern() const { return immutableState()->strokePattern(); } |
| 115 void setStrokePattern(PassRefPtr<Pattern>, float alpha = 1); | 114 void setStrokePattern(PassRefPtr<Pattern>, float alpha = 1); |
| 116 | 115 |
| 117 Gradient* strokeGradient() const { return immutableState()->strokeGradient()
; } | 116 Gradient* strokeGradient() const { return immutableState()->strokeGradient()
; } |
| 118 void setStrokeGradient(PassRefPtr<Gradient>, float alpha = 1); | 117 void setStrokeGradient(PassRefPtr<Gradient>, float alpha = 1); |
| 119 | 118 |
| 120 void setLineCap(LineCap cap) { mutableState()->setLineCap(cap); } | 119 void setLineCap(LineCap cap) { mutableState()->setLineCap(cap); } |
| 121 void setLineDash(const DashArray& dashes, float dashOffset) { mutableState()
->setLineDash(dashes, dashOffset); } | 120 void setLineDash(const DashArray& dashes, float dashOffset) { mutableState()
->setLineDash(dashes, dashOffset); } |
| 122 void setLineJoin(LineJoin join) { mutableState()->setLineJoin(join); } | 121 void setLineJoin(LineJoin join) { mutableState()->setLineJoin(join); } |
| 123 void setMiterLimit(float limit) { mutableState()->setMiterLimit(limit); } | 122 void setMiterLimit(float limit) { mutableState()->setMiterLimit(limit); } |
| 124 | 123 |
| 125 Color fillColor() const { return immutableState()->fillColor(); } | 124 Color fillColor() const { return immutableState()->fillColor(); } |
| 126 void setFillColor(const Color& color) { mutableState()->setFillColor(color);
} | 125 void setFillColor(const Color& color) { mutableState()->setFillColor(color);
} |
| 127 | 126 |
| 128 void setFillPattern(PassRefPtr<Pattern>, float alpha = 1); | 127 void setFillPattern(PassRefPtr<Pattern>, float alpha = 1); |
| 129 | 128 |
| 130 void setFillGradient(PassRefPtr<Gradient>, float alpha = 1); | 129 void setFillGradient(PassRefPtr<Gradient>, float alpha = 1); |
| 131 | 130 |
| 132 SkDrawLooper* drawLooper() const { return immutableState()->drawLooper(); } | 131 SkDrawLooper* drawLooper() const { return immutableState()->drawLooper(); } |
| 133 | 132 |
| 134 SkMatrix getTotalMatrix() const; | 133 SkMatrix getTotalMatrix() const; |
| 135 | 134 |
| 136 void setShouldAntialias(bool antialias) { mutableState()->setShouldAntialias
(antialias); } | 135 void setShouldAntialias(bool antialias) { mutableState()->setShouldAntialias
(antialias); } |
| 137 bool shouldAntialias() const { return immutableState()->shouldAntialias(); } | 136 bool shouldAntialias() const { return immutableState()->shouldAntialias(); } |
| 138 | 137 |
| 139 // Disable the anti-aliasing optimization for scales/multiple-of-90-degrees | |
| 140 // rotations of thin ("hairline") images. | |
| 141 // Note: This will only be reliable when the device pixel scale/ratio is | |
| 142 // fixed (e.g. when drawing to context backed by an ImageBuffer). | |
| 143 void disableAntialiasingOptimizationForHairlineImages() { ASSERT(!isRecordin
g()); m_antialiasHairlineImages = true; } | |
| 144 bool shouldAntialiasHairlineImages() const { return m_antialiasHairlineImage
s; } | |
| 145 | |
| 146 void setShouldClampToSourceRect(bool clampToSourceRect) { mutableState()->se
tShouldClampToSourceRect(clampToSourceRect); } | |
| 147 bool shouldClampToSourceRect() const { return immutableState()->shouldClampT
oSourceRect(); } | |
| 148 | |
| 149 void setTextDrawingMode(TextDrawingModeFlags mode) { mutableState()->setText
DrawingMode(mode); } | 138 void setTextDrawingMode(TextDrawingModeFlags mode) { mutableState()->setText
DrawingMode(mode); } |
| 150 TextDrawingModeFlags textDrawingMode() const { return immutableState()->text
DrawingMode(); } | 139 TextDrawingModeFlags textDrawingMode() const { return immutableState()->text
DrawingMode(); } |
| 151 | 140 |
| 152 void setAlphaAsFloat(float alpha) { mutableState()->setAlphaAsFloat(alpha);} | |
| 153 int getNormalizedAlpha() const | |
| 154 { | |
| 155 int alpha = immutableState()->alpha(); | |
| 156 return alpha > 255 ? 255 : alpha; | |
| 157 } | |
| 158 | |
| 159 void setImageInterpolationQuality(InterpolationQuality quality) { mutableSta
te()->setInterpolationQuality(quality); } | 141 void setImageInterpolationQuality(InterpolationQuality quality) { mutableSta
te()->setInterpolationQuality(quality); } |
| 160 InterpolationQuality imageInterpolationQuality() const { return immutableSta
te()->interpolationQuality(); } | 142 InterpolationQuality imageInterpolationQuality() const { return immutableSta
te()->interpolationQuality(); } |
| 161 | 143 |
| 162 // Do not use these methods: they are deprecated/scheduled for removal. | |
| 163 void setCompositeOperation(SkXfermode::Mode); | |
| 164 SkXfermode::Mode compositeOperation() const; | |
| 165 | |
| 166 // Specify the device scale factor which may change the way document markers | 144 // Specify the device scale factor which may change the way document markers |
| 167 // and fonts are rendered. | 145 // and fonts are rendered. |
| 168 void setDeviceScaleFactor(float factor) { m_deviceScaleFactor = factor; } | 146 void setDeviceScaleFactor(float factor) { m_deviceScaleFactor = factor; } |
| 169 float deviceScaleFactor() const { return m_deviceScaleFactor; } | 147 float deviceScaleFactor() const { return m_deviceScaleFactor; } |
| 170 | 148 |
| 171 // Returns if the context is a printing context instead of a display | 149 // Returns if the context is a printing context instead of a display |
| 172 // context. Bitmap shouldn't be resampled when printing to keep the best | 150 // context. Bitmap shouldn't be resampled when printing to keep the best |
| 173 // possible quality. | 151 // possible quality. |
| 174 bool printing() const { return m_printing; } | 152 bool printing() const { return m_printing; } |
| 175 void setPrinting(bool printing) { m_printing = printing; } | 153 void setPrinting(bool printing) { m_printing = printing; } |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 SkXfermode::Mode = SkXfermode::kSrcOver_Mode, const IntSize& repeatSpaci
ng = IntSize()); | 195 SkXfermode::Mode = SkXfermode::kSrcOver_Mode, const IntSize& repeatSpaci
ng = IntSize()); |
| 218 void drawTiledImage(Image*, const IntRect& destRect, const IntRect& srcRect, | 196 void drawTiledImage(Image*, const IntRect& destRect, const IntRect& srcRect, |
| 219 const FloatSize& tileScaleFactor, Image::TileRule hRule = Image::Stretch
Tile, Image::TileRule vRule = Image::StretchTile, | 197 const FloatSize& tileScaleFactor, Image::TileRule hRule = Image::Stretch
Tile, Image::TileRule vRule = Image::StretchTile, |
| 220 SkXfermode::Mode = SkXfermode::kSrcOver_Mode); | 198 SkXfermode::Mode = SkXfermode::kSrcOver_Mode); |
| 221 | 199 |
| 222 void drawImageBuffer(ImageBuffer*, const FloatRect& destRect, const FloatRec
t* srcRect = 0, SkXfermode::Mode = SkXfermode::kSrcOver_Mode); | 200 void drawImageBuffer(ImageBuffer*, const FloatRect& destRect, const FloatRec
t* srcRect = 0, SkXfermode::Mode = SkXfermode::kSrcOver_Mode); |
| 223 | 201 |
| 224 // These methods write to the canvas. | 202 // These methods write to the canvas. |
| 225 // Also drawLine(const IntPoint& point1, const IntPoint& point2) and fillRou
ndedRect | 203 // Also drawLine(const IntPoint& point1, const IntPoint& point2) and fillRou
ndedRect |
| 226 void writePixels(const SkImageInfo&, const void* pixels, size_t rowBytes, in
t x, int y); | 204 void writePixels(const SkImageInfo&, const void* pixels, size_t rowBytes, in
t x, int y); |
| 227 void drawBitmapRect(const SkBitmap&, const SkRect*, const SkRect&, const SkP
aint* = 0); | |
| 228 void drawOval(const SkRect&, const SkPaint&); | 205 void drawOval(const SkRect&, const SkPaint&); |
| 229 void drawPath(const SkPath&, const SkPaint&); | 206 void drawPath(const SkPath&, const SkPaint&); |
| 230 void drawRect(const SkRect&, const SkPaint&); | 207 void drawRect(const SkRect&, const SkPaint&); |
| 231 | 208 |
| 232 void clip(const IntRect& rect) { clipRect(rect); } | 209 void clip(const IntRect& rect) { clipRect(rect); } |
| 233 void clip(const FloatRect& rect) { clipRect(rect); } | 210 void clip(const FloatRect& rect) { clipRect(rect); } |
| 234 void clipRoundedRect(const FloatRoundedRect&, SkRegion::Op = SkRegion::kInte
rsect_Op); | 211 void clipRoundedRect(const FloatRoundedRect&, SkRegion::Op = SkRegion::kInte
rsect_Op); |
| 235 void clipOut(const IntRect& rect) { clipRect(rect, NotAntiAliased, SkRegion:
:kDifference_Op); } | 212 void clipOut(const IntRect& rect) { clipRect(rect, NotAntiAliased, SkRegion:
:kDifference_Op); } |
| 236 void clipOut(const FloatRect& rect) { clipRect(rect, NotAntiAliased, SkRegio
n::kDifference_Op); } | 213 void clipOut(const FloatRect& rect) { clipRect(rect, NotAntiAliased, SkRegio
n::kDifference_Op); } |
| 237 void clipOut(const Path&); | 214 void clipOut(const Path&); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 261 | 238 |
| 262 // Instead of being dispatched to the active canvas, draw commands following
beginRecording() | 239 // Instead of being dispatched to the active canvas, draw commands following
beginRecording() |
| 263 // are stored in a display list that can be replayed at a later time. Pass i
n the bounding | 240 // are stored in a display list that can be replayed at a later time. Pass i
n the bounding |
| 264 // rectangle for the content in the list. | 241 // rectangle for the content in the list. |
| 265 void beginRecording(const FloatRect&, uint32_t = 0); | 242 void beginRecording(const FloatRect&, uint32_t = 0); |
| 266 PassRefPtr<const SkPicture> endRecording(); | 243 PassRefPtr<const SkPicture> endRecording(); |
| 267 | 244 |
| 268 void setShadow(const FloatSize& offset, float blur, const Color&, | 245 void setShadow(const FloatSize& offset, float blur, const Color&, |
| 269 DrawLooperBuilder::ShadowTransformMode = DrawLooperBuilder::ShadowRespec
tsTransforms, | 246 DrawLooperBuilder::ShadowTransformMode = DrawLooperBuilder::ShadowRespec
tsTransforms, |
| 270 DrawLooperBuilder::ShadowAlphaMode = DrawLooperBuilder::ShadowRespectsAl
pha, ShadowMode = DrawShadowAndForeground); | 247 DrawLooperBuilder::ShadowAlphaMode = DrawLooperBuilder::ShadowRespectsAl
pha, ShadowMode = DrawShadowAndForeground); |
| 271 void clearShadow() { clearDrawLooper(); clearDropShadowImageFilter(); } | |
| 272 void setDropShadowImageFilter(PassRefPtr<SkImageFilter>); | |
| 273 | 248 |
| 274 // It is assumed that this draw looper is used only for shadows | 249 // It is assumed that this draw looper is used only for shadows |
| 275 // (i.e. a draw looper is set if and only if there is a shadow). | 250 // (i.e. a draw looper is set if and only if there is a shadow). |
| 276 // The builder passed into this method will be destroyed. | 251 // The builder passed into this method will be destroyed. |
| 277 void setDrawLooper(PassOwnPtr<DrawLooperBuilder>); | 252 void setDrawLooper(PassOwnPtr<DrawLooperBuilder>); |
| 278 void setDrawLooper(PassRefPtr<SkDrawLooper> looper) { mutableState()->setDra
wLooper(looper); } | |
| 279 void clearDrawLooper(); | 253 void clearDrawLooper(); |
| 280 | 254 |
| 281 void drawFocusRing(const Vector<IntRect>&, int width, int offset, const Colo
r&); | 255 void drawFocusRing(const Vector<IntRect>&, int width, int offset, const Colo
r&); |
| 282 void drawFocusRing(const Path&, int width, int offset, const Color&); | 256 void drawFocusRing(const Path&, int width, int offset, const Color&); |
| 283 | 257 |
| 284 enum Edge { | 258 enum Edge { |
| 285 NoEdge = 0, | 259 NoEdge = 0, |
| 286 TopEdge = 1 << 1, | 260 TopEdge = 1 << 1, |
| 287 RightEdge = 1 << 2, | 261 RightEdge = 1 << 2, |
| 288 BottomEdge = 1 << 3, | 262 BottomEdge = 1 << 3, |
| 289 LeftEdge = 1 << 4 | 263 LeftEdge = 1 << 4 |
| 290 }; | 264 }; |
| 291 typedef unsigned Edges; | 265 typedef unsigned Edges; |
| 292 void drawInnerShadow(const FloatRoundedRect&, const Color& shadowColor, cons
t IntSize shadowOffset, int shadowBlur, int shadowSpread, Edges clippedEdges = N
oEdge); | 266 void drawInnerShadow(const FloatRoundedRect&, const Color& shadowColor, cons
t IntSize shadowOffset, int shadowBlur, int shadowSpread, Edges clippedEdges = N
oEdge); |
| 293 | 267 |
| 268 const SkPaint& fillPaint() const { return immutableState()->fillPaint(); } |
| 269 |
| 294 // ---------- Transformation methods ----------------- | 270 // ---------- Transformation methods ----------------- |
| 295 // Note that the getCTM method returns only the current transform from Blink
's perspective, | 271 // Note that the getCTM method returns only the current transform from Blink
's perspective, |
| 296 // which is not the final transform used to place content on screen. It cann
ot be relied upon | 272 // which is not the final transform used to place content on screen. It cann
ot be relied upon |
| 297 // for testing where a point will appear on screen or how large it will be. | 273 // for testing where a point will appear on screen or how large it will be. |
| 298 AffineTransform getCTM() const; | 274 AffineTransform getCTM() const; |
| 299 void concatCTM(const AffineTransform&); | 275 void concatCTM(const AffineTransform&); |
| 300 void setCTM(const AffineTransform&); | 276 void setCTM(const AffineTransform&); |
| 301 void setMatrix(const SkMatrix&); | 277 void setMatrix(const SkMatrix&); |
| 302 | 278 |
| 303 void scale(float x, float y); | 279 void scale(float x, float y); |
| 304 void rotate(float angleInRadians); | 280 void rotate(float angleInRadians); |
| 305 void translate(float x, float y); | 281 void translate(float x, float y); |
| 306 // ---------- End transformation methods ----------------- | 282 // ---------- End transformation methods ----------------- |
| 307 | 283 |
| 284 SkFilterQuality computeFilterQuality(Image*, const FloatRect& dest, const Fl
oatRect& src) const; |
| 285 bool shouldAntialiasImages() { return shouldAntialias() && !getTotalMatrix()
.rectStaysRect();} |
| 286 |
| 308 // URL drawing | 287 // URL drawing |
| 309 void setURLForRect(const KURL&, const IntRect&); | 288 void setURLForRect(const KURL&, const IntRect&); |
| 310 void setURLFragmentForRect(const String& name, const IntRect&); | 289 void setURLFragmentForRect(const String& name, const IntRect&); |
| 311 void addURLTargetAtPoint(const String& name, const IntPoint&); | 290 void addURLTargetAtPoint(const String& name, const IntPoint&); |
| 312 | 291 |
| 313 static void adjustLineToPixelBoundaries(FloatPoint& p1, FloatPoint& p2, floa
t strokeWidth, StrokeStyle); | 292 static void adjustLineToPixelBoundaries(FloatPoint& p1, FloatPoint& p2, floa
t strokeWidth, StrokeStyle); |
| 314 | 293 |
| 315 // This method can potentially push saves onto the canvas. It returns the in
itial save count, | |
| 316 // and should be balanced with a call to context->canvas()->restoreToCount(i
nitialSaveCount). | |
| 317 WARN_UNUSED_RETURN int preparePaintForDrawRectToRect( | |
| 318 SkPaint*, | |
| 319 const SkRect& srcRect, | |
| 320 const SkRect& destRect, | |
| 321 SkXfermode::Mode, | |
| 322 bool isBitmapWithAlpha, | |
| 323 bool isLazyDecoded = false, | |
| 324 bool isDataComplete = true) const; | |
| 325 | |
| 326 static int focusRingOutsetExtent(int offset, int width) | 294 static int focusRingOutsetExtent(int offset, int width) |
| 327 { | 295 { |
| 328 return focusRingOutset(offset) + (focusRingWidth(width) + 1) / 2; | 296 return focusRingOutset(offset) + (focusRingWidth(width) + 1) / 2; |
| 329 } | 297 } |
| 330 | 298 |
| 331 // public decl needed for OwnPtr wrapper. | 299 // public decl needed for OwnPtr wrapper. |
| 332 class RecordingState; | 300 class RecordingState; |
| 333 | 301 |
| 334 #if ENABLE(ASSERT) | 302 #if ENABLE(ASSERT) |
| 335 void setInDrawingRecorder(bool); | 303 void setInDrawingRecorder(bool); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 363 static SkPMColor antiColors1(int); | 331 static SkPMColor antiColors1(int); |
| 364 static SkPMColor antiColors2(int); | 332 static SkPMColor antiColors2(int); |
| 365 static void draw1xMarker(SkBitmap*, int); | 333 static void draw1xMarker(SkBitmap*, int); |
| 366 static void draw2xMarker(SkBitmap*, int); | 334 static void draw2xMarker(SkBitmap*, int); |
| 367 #endif | 335 #endif |
| 368 | 336 |
| 369 void saveLayer(const SkRect* bounds, const SkPaint*); | 337 void saveLayer(const SkRect* bounds, const SkPaint*); |
| 370 void restoreLayer(); | 338 void restoreLayer(); |
| 371 | 339 |
| 372 // Helpers for drawing a focus ring (drawFocusRing) | 340 // Helpers for drawing a focus ring (drawFocusRing) |
| 373 float prepareFocusRingPaint(SkPaint&, const Color&, int width) const; | |
| 374 void drawFocusRingPath(const SkPath&, const Color&, int width); | 341 void drawFocusRingPath(const SkPath&, const Color&, int width); |
| 375 void drawFocusRingRect(const SkRect&, const Color&, int width); | 342 void drawFocusRingRect(const SkRect&, const Color&, int width); |
| 376 | 343 |
| 377 // SkCanvas wrappers. | 344 // SkCanvas wrappers. |
| 378 void clipRRect(const SkRRect&, AntiAliasingMode = NotAntiAliased, SkRegion::
Op = SkRegion::kIntersect_Op); | 345 void clipRRect(const SkRRect&, AntiAliasingMode = NotAntiAliased, SkRegion::
Op = SkRegion::kIntersect_Op); |
| 379 void concat(const SkMatrix&); | 346 void concat(const SkMatrix&); |
| 380 void drawRRect(const SkRRect&, const SkPaint&); | 347 void drawRRect(const SkRRect&, const SkPaint&); |
| 381 | 348 |
| 382 void clearDropShadowImageFilter(); | |
| 383 SkImageFilter* dropShadowImageFilter() const { return immutableState()->drop
ShadowImageFilter(); } | |
| 384 | |
| 385 // Apply deferred paint state saves | 349 // Apply deferred paint state saves |
| 386 void realizePaintSave() | 350 void realizePaintSave() |
| 387 { | 351 { |
| 388 if (contextDisabled()) | 352 if (contextDisabled()) |
| 389 return; | 353 return; |
| 390 | 354 |
| 391 if (m_paintState->saveCount()) { | 355 if (m_paintState->saveCount()) { |
| 392 m_paintState->decrementSaveCount(); | 356 m_paintState->decrementSaveCount(); |
| 393 ++m_paintStateIndex; | 357 ++m_paintStateIndex; |
| 394 if (m_paintStateStack.size() == m_paintStateIndex) { | 358 if (m_paintStateStack.size() == m_paintStateIndex) { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 bool m_disableDestructionChecks; | 398 bool m_disableDestructionChecks; |
| 435 bool m_inDrawingRecorder; | 399 bool m_inDrawingRecorder; |
| 436 #endif | 400 #endif |
| 437 | 401 |
| 438 const DisabledMode m_disabledState; | 402 const DisabledMode m_disabledState; |
| 439 | 403 |
| 440 float m_deviceScaleFactor; | 404 float m_deviceScaleFactor; |
| 441 | 405 |
| 442 unsigned m_accelerated : 1; | 406 unsigned m_accelerated : 1; |
| 443 unsigned m_printing : 1; | 407 unsigned m_printing : 1; |
| 444 unsigned m_antialiasHairlineImages : 1; | |
| 445 }; | 408 }; |
| 446 | 409 |
| 447 } // namespace blink | 410 } // namespace blink |
| 448 | 411 |
| 449 #endif // GraphicsContext_h | 412 #endif // GraphicsContext_h |
| OLD | NEW |