| 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 class PaintController; | 63 class PaintController; |
| 64 class Path; | 64 class Path; |
| 65 | 65 |
| 66 class PLATFORM_EXPORT GraphicsContext { | 66 class PLATFORM_EXPORT GraphicsContext { |
| 67 WTF_MAKE_NONCOPYABLE(GraphicsContext); | 67 WTF_MAKE_NONCOPYABLE(GraphicsContext); |
| 68 USING_FAST_MALLOC(GraphicsContext); | 68 USING_FAST_MALLOC(GraphicsContext); |
| 69 | 69 |
| 70 public: | 70 public: |
| 71 enum DisabledMode { | 71 enum DisabledMode { |
| 72 NothingDisabled = 0, // Run as normal. | 72 NothingDisabled = 0, // Run as normal. |
| 73 FullyDisabled = | 73 FullyDisabled = 1 // Do absolutely minimal work to remove the cost of |
| 74 1 // Do absolutely minimal work to remove the cost of the context from
performance tests. | 74 // the context from performance tests. |
| 75 }; | 75 }; |
| 76 | 76 |
| 77 explicit GraphicsContext(PaintController&, | 77 explicit GraphicsContext(PaintController&, |
| 78 DisabledMode = NothingDisabled, | 78 DisabledMode = NothingDisabled, |
| 79 SkMetaData* = 0); | 79 SkMetaData* = 0); |
| 80 | 80 |
| 81 ~GraphicsContext(); | 81 ~GraphicsContext(); |
| 82 | 82 |
| 83 SkCanvas* canvas() { return m_canvas; } | 83 SkCanvas* canvas() { return m_canvas; } |
| 84 const SkCanvas* canvas() const { return m_canvas; } | 84 const SkCanvas* canvas() const { return m_canvas; } |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 const FloatSize& repeatSpacing = FloatSize()); | 207 const FloatSize& repeatSpacing = FloatSize()); |
| 208 void drawTiledImage(Image*, | 208 void drawTiledImage(Image*, |
| 209 const FloatRect& destRect, | 209 const FloatRect& destRect, |
| 210 const FloatRect& srcRect, | 210 const FloatRect& srcRect, |
| 211 const FloatSize& tileScaleFactor, | 211 const FloatSize& tileScaleFactor, |
| 212 Image::TileRule hRule = Image::StretchTile, | 212 Image::TileRule hRule = Image::StretchTile, |
| 213 Image::TileRule vRule = Image::StretchTile, | 213 Image::TileRule vRule = Image::StretchTile, |
| 214 SkXfermode::Mode = SkXfermode::kSrcOver_Mode); | 214 SkXfermode::Mode = SkXfermode::kSrcOver_Mode); |
| 215 | 215 |
| 216 // These methods write to the canvas. | 216 // These methods write to the canvas. |
| 217 // Also drawLine(const IntPoint& point1, const IntPoint& point2) and fillRound
edRect | 217 // Also drawLine(const IntPoint& point1, const IntPoint& point2) and |
| 218 // fillRoundedRect(). |
| 218 void drawOval(const SkRect&, const SkPaint&); | 219 void drawOval(const SkRect&, const SkPaint&); |
| 219 void drawPath(const SkPath&, const SkPaint&); | 220 void drawPath(const SkPath&, const SkPaint&); |
| 220 void drawRect(const SkRect&, const SkPaint&); | 221 void drawRect(const SkRect&, const SkPaint&); |
| 221 void drawRRect(const SkRRect&, const SkPaint&); | 222 void drawRRect(const SkRRect&, const SkPaint&); |
| 222 | 223 |
| 223 void clip(const IntRect& rect) { clipRect(rect); } | 224 void clip(const IntRect& rect) { clipRect(rect); } |
| 224 void clip(const FloatRect& rect) { clipRect(rect); } | 225 void clip(const FloatRect& rect) { clipRect(rect); } |
| 225 void clipRoundedRect(const FloatRoundedRect&, | 226 void clipRoundedRect(const FloatRoundedRect&, |
| 226 SkRegion::Op = SkRegion::kIntersect_Op, | 227 SkRegion::Op = SkRegion::kIntersect_Op, |
| 227 AntiAliasingMode = AntiAliased); | 228 AntiAliasingMode = AntiAliased); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 | 265 |
| 265 void drawLineForText(const FloatPoint&, float width, bool printing); | 266 void drawLineForText(const FloatPoint&, float width, bool printing); |
| 266 enum DocumentMarkerLineStyle { | 267 enum DocumentMarkerLineStyle { |
| 267 DocumentMarkerSpellingLineStyle, | 268 DocumentMarkerSpellingLineStyle, |
| 268 DocumentMarkerGrammarLineStyle | 269 DocumentMarkerGrammarLineStyle |
| 269 }; | 270 }; |
| 270 void drawLineForDocumentMarker(const FloatPoint&, | 271 void drawLineForDocumentMarker(const FloatPoint&, |
| 271 float width, | 272 float width, |
| 272 DocumentMarkerLineStyle); | 273 DocumentMarkerLineStyle); |
| 273 | 274 |
| 274 // beginLayer()/endLayer() behaves like save()/restore() for CTM and clip stat
es. | 275 // beginLayer()/endLayer() behave like save()/restore() for CTM and clip |
| 275 // Apply SkXfermode::Mode when the layer is composited on the backdrop (i.e. e
ndLayer()). | 276 // states. Apply SkXfermode::Mode when the layer is composited on the backdrop |
| 277 // (i.e. endLayer()). |
| 276 void beginLayer(float opacity = 1.0f, | 278 void beginLayer(float opacity = 1.0f, |
| 277 SkXfermode::Mode = SkXfermode::kSrcOver_Mode, | 279 SkXfermode::Mode = SkXfermode::kSrcOver_Mode, |
| 278 const FloatRect* = 0, | 280 const FloatRect* = 0, |
| 279 ColorFilter = ColorFilterNone, | 281 ColorFilter = ColorFilterNone, |
| 280 sk_sp<SkImageFilter> = nullptr); | 282 sk_sp<SkImageFilter> = nullptr); |
| 281 void endLayer(); | 283 void endLayer(); |
| 282 | 284 |
| 283 // Instead of being dispatched to the active canvas, draw commands following b
eginRecording() | 285 // Instead of being dispatched to the active canvas, draw commands following |
| 284 // are stored in a display list that can be replayed at a later time. Pass in
the bounding | 286 // beginRecording() are stored in a display list that can be replayed at a |
| 285 // rectangle for the content in the list. | 287 // later time. Pass in the bounding rectangle for the content in the list. |
| 286 void beginRecording(const FloatRect&); | 288 void beginRecording(const FloatRect&); |
| 287 // Returns a picture with any recorded draw commands since the prerequisite ca
ll to | 289 |
| 288 // beginRecording(). The picture is guaranteed to be non-null (but not necess
arily non-empty), | 290 // Returns a picture with any recorded draw commands since the prerequisite |
| 289 // even when the context is disabled. | 291 // call to beginRecording(). The picture is guaranteed to be non-null (but |
| 292 // not necessarily non-empty), even when the context is disabled. |
| 290 sk_sp<SkPicture> endRecording(); | 293 sk_sp<SkPicture> endRecording(); |
| 291 | 294 |
| 292 void setShadow(const FloatSize& offset, | 295 void setShadow(const FloatSize& offset, |
| 293 float blur, | 296 float blur, |
| 294 const Color&, | 297 const Color&, |
| 295 DrawLooperBuilder::ShadowTransformMode = | 298 DrawLooperBuilder::ShadowTransformMode = |
| 296 DrawLooperBuilder::ShadowRespectsTransforms, | 299 DrawLooperBuilder::ShadowRespectsTransforms, |
| 297 DrawLooperBuilder::ShadowAlphaMode = | 300 DrawLooperBuilder::ShadowAlphaMode = |
| 298 DrawLooperBuilder::ShadowRespectsAlpha, | 301 DrawLooperBuilder::ShadowRespectsAlpha, |
| 299 ShadowMode = DrawShadowAndForeground); | 302 ShadowMode = DrawShadowAndForeground); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 void translate(float x, float y); | 338 void translate(float x, float y); |
| 336 // ---------- End transformation methods ----------------- | 339 // ---------- End transformation methods ----------------- |
| 337 | 340 |
| 338 SkFilterQuality computeFilterQuality(Image*, | 341 SkFilterQuality computeFilterQuality(Image*, |
| 339 const FloatRect& dest, | 342 const FloatRect& dest, |
| 340 const FloatRect& src) const; | 343 const FloatRect& src) const; |
| 341 | 344 |
| 342 // Sets target URL of a clickable area. | 345 // Sets target URL of a clickable area. |
| 343 void setURLForRect(const KURL&, const IntRect&); | 346 void setURLForRect(const KURL&, const IntRect&); |
| 344 | 347 |
| 345 // Sets destination of a URL fragment (in a URL pointing to the same web page)
of a clickable area. | 348 // Sets the destination of a clickable area of a URL fragment (in a URL |
| 346 // When the area is clicked, the page should be scrolled to the location set b
y setURLDestinationLocation() | 349 // pointing to the same web page). When the area is clicked, the page should |
| 347 // for the destination whose name equals the fragment. | 350 // be scrolled to the location set by setURLDestinationLocation() for the |
| 351 // destination whose name is |name|. |
| 348 void setURLFragmentForRect(const String& name, const IntRect&); | 352 void setURLFragmentForRect(const String& name, const IntRect&); |
| 349 | 353 |
| 350 // Sets location of a URL destination (a.k.a. anchor) in the page. | 354 // Sets location of a URL destination (a.k.a. anchor) in the page. |
| 351 void setURLDestinationLocation(const String& name, const IntPoint&); | 355 void setURLDestinationLocation(const String& name, const IntPoint&); |
| 352 | 356 |
| 353 static void adjustLineToPixelBoundaries(FloatPoint& p1, | 357 static void adjustLineToPixelBoundaries(FloatPoint& p1, |
| 354 FloatPoint& p2, | 358 FloatPoint& p2, |
| 355 float strokeWidth, | 359 float strokeWidth, |
| 356 StrokeStyle); | 360 StrokeStyle); |
| 357 | 361 |
| 358 static int focusRingOutsetExtent(int offset, int width) { | 362 static int focusRingOutsetExtent(int offset, int width) { |
| 359 // Unlike normal outlines (whole width is outside of the offset), focus ring
s are drawn with the | 363 // Unlike normal outlines (whole width is outside of the offset), focus |
| 360 // center of the path aligned with the offset, so only half of the width is
outside of the offset. | 364 // rings are drawn with the center of the path aligned with the offset, so |
| 365 // only half of the width is outside of the offset. |
| 361 return focusRingOffset(offset) + (focusRingWidth(width) + 1) / 2; | 366 return focusRingOffset(offset) + (focusRingWidth(width) + 1) / 2; |
| 362 } | 367 } |
| 363 | 368 |
| 364 #if OS(MACOSX) | 369 #if OS(MACOSX) |
| 365 static int focusRingWidth(int width) { return width; } | 370 static int focusRingWidth(int width) { return width; } |
| 366 #else | 371 #else |
| 367 static int focusRingWidth(int width) { return 1; } | 372 static int focusRingWidth(int width) { return 1; } |
| 368 #endif | 373 #endif |
| 369 | 374 |
| 370 #if DCHECK_IS_ON() | 375 #if DCHECK_IS_ON() |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 const FloatRoundedRect& roundedHoleRect, | 437 const FloatRoundedRect& roundedHoleRect, |
| 433 const Color&); | 438 const Color&); |
| 434 | 439 |
| 435 const SkMetaData& metaData() const { return m_metaData; } | 440 const SkMetaData& metaData() const { return m_metaData; } |
| 436 | 441 |
| 437 // null indicates painting is contextDisabled. Never delete this object. | 442 // null indicates painting is contextDisabled. Never delete this object. |
| 438 SkCanvas* m_canvas; | 443 SkCanvas* m_canvas; |
| 439 | 444 |
| 440 PaintController& m_paintController; | 445 PaintController& m_paintController; |
| 441 | 446 |
| 442 // Paint states stack. Enables local drawing state change with save()/restore(
) calls. | 447 // Paint states stack. The state controls the appearance of drawn content, so |
| 443 // This state controls the appearance of drawn content. | 448 // this stack enables local drawing state changes with save()/restore() calls. |
| 444 // We do not delete from this stack to avoid memory churn. | 449 // We do not delete from this stack to avoid memory churn. |
| 445 Vector<std::unique_ptr<GraphicsContextState>> m_paintStateStack; | 450 Vector<std::unique_ptr<GraphicsContextState>> m_paintStateStack; |
| 451 |
| 446 // Current index on the stack. May not be the last thing on the stack. | 452 // Current index on the stack. May not be the last thing on the stack. |
| 447 unsigned m_paintStateIndex; | 453 unsigned m_paintStateIndex; |
| 454 |
| 448 // Raw pointer to the current state. | 455 // Raw pointer to the current state. |
| 449 GraphicsContextState* m_paintState; | 456 GraphicsContextState* m_paintState; |
| 450 | 457 |
| 451 SkPictureRecorder m_pictureRecorder; | 458 SkPictureRecorder m_pictureRecorder; |
| 452 | 459 |
| 453 SkMetaData m_metaData; | 460 SkMetaData m_metaData; |
| 454 | 461 |
| 455 #if DCHECK_IS_ON() | 462 #if DCHECK_IS_ON() |
| 456 unsigned m_layerCount; | 463 unsigned m_layerCount; |
| 457 bool m_disableDestructionChecks; | 464 bool m_disableDestructionChecks; |
| 458 bool m_inDrawingRecorder; | 465 bool m_inDrawingRecorder; |
| 459 #endif | 466 #endif |
| 460 | 467 |
| 461 const DisabledMode m_disabledState; | 468 const DisabledMode m_disabledState; |
| 462 | 469 |
| 463 float m_deviceScaleFactor; | 470 float m_deviceScaleFactor; |
| 464 | 471 |
| 465 unsigned m_printing : 1; | 472 unsigned m_printing : 1; |
| 466 unsigned m_hasMetaData : 1; | 473 unsigned m_hasMetaData : 1; |
| 467 }; | 474 }; |
| 468 | 475 |
| 469 } // namespace blink | 476 } // namespace blink |
| 470 | 477 |
| 471 #endif // GraphicsContext_h | 478 #endif // GraphicsContext_h |
| OLD | NEW |