| 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 17 matching lines...) Expand all Loading... |
| 28 #ifndef GraphicsContext_h | 28 #ifndef GraphicsContext_h |
| 29 #define GraphicsContext_h | 29 #define GraphicsContext_h |
| 30 | 30 |
| 31 #include "platform/PlatformExport.h" | 31 #include "platform/PlatformExport.h" |
| 32 #include "platform/fonts/Font.h" | 32 #include "platform/fonts/Font.h" |
| 33 #include "platform/graphics/ColorBehavior.h" | 33 #include "platform/graphics/ColorBehavior.h" |
| 34 #include "platform/graphics/DashArray.h" | 34 #include "platform/graphics/DashArray.h" |
| 35 #include "platform/graphics/DrawLooperBuilder.h" | 35 #include "platform/graphics/DrawLooperBuilder.h" |
| 36 #include "platform/graphics/GraphicsContextState.h" | 36 #include "platform/graphics/GraphicsContextState.h" |
| 37 #include "platform/graphics/ImageOrientation.h" | 37 #include "platform/graphics/ImageOrientation.h" |
| 38 #include "platform/graphics/paint/PaintRecord.h" |
| 39 #include "platform/graphics/paint/PaintRecorder.h" |
| 38 #include "platform/graphics/skia/SkiaUtils.h" | 40 #include "platform/graphics/skia/SkiaUtils.h" |
| 39 #include "third_party/skia/include/core/SkClipOp.h" | 41 #include "third_party/skia/include/core/SkClipOp.h" |
| 42 #include "third_party/skia/include/core/SkImageFilter.h" |
| 40 #include "third_party/skia/include/core/SkMetaData.h" | 43 #include "third_party/skia/include/core/SkMetaData.h" |
| 41 #include "third_party/skia/include/core/SkPictureRecorder.h" | |
| 42 #include "third_party/skia/include/core/SkRefCnt.h" | 44 #include "third_party/skia/include/core/SkRefCnt.h" |
| 43 #include "wtf/Allocator.h" | 45 #include "wtf/Allocator.h" |
| 44 #include "wtf/Forward.h" | 46 #include "wtf/Forward.h" |
| 45 #include "wtf/Noncopyable.h" | 47 #include "wtf/Noncopyable.h" |
| 46 #include <memory> | 48 #include <memory> |
| 47 | 49 |
| 48 class SkBitmap; | 50 class SkBitmap; |
| 49 class SkPaint; | |
| 50 class SkPath; | 51 class SkPath; |
| 51 class SkPicture; | |
| 52 class SkRRect; | 52 class SkRRect; |
| 53 struct SkRect; | 53 struct SkRect; |
| 54 | 54 |
| 55 namespace blink { | 55 namespace blink { |
| 56 | 56 |
| 57 class FloatRect; | 57 class FloatRect; |
| 58 class FloatRoundedRect; | 58 class FloatRoundedRect; |
| 59 class KURL; | 59 class KURL; |
| 60 class PaintController; | 60 class PaintController; |
| 61 class Path; | 61 class Path; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 72 }; | 72 }; |
| 73 | 73 |
| 74 explicit GraphicsContext( | 74 explicit GraphicsContext( |
| 75 PaintController&, | 75 PaintController&, |
| 76 DisabledMode = NothingDisabled, | 76 DisabledMode = NothingDisabled, |
| 77 SkMetaData* = 0, | 77 SkMetaData* = 0, |
| 78 ColorBehavior = ColorBehavior::transformToGlobalTarget()); | 78 ColorBehavior = ColorBehavior::transformToGlobalTarget()); |
| 79 | 79 |
| 80 ~GraphicsContext(); | 80 ~GraphicsContext(); |
| 81 | 81 |
| 82 SkCanvas* canvas() { return m_canvas; } | 82 PaintCanvas* canvas() { return m_canvas; } |
| 83 const SkCanvas* canvas() const { return m_canvas; } | 83 const PaintCanvas* canvas() const { return m_canvas; } |
| 84 | 84 |
| 85 PaintController& getPaintController() { return m_paintController; } | 85 PaintController& getPaintController() { return m_paintController; } |
| 86 const ColorBehavior& getColorBehavior() const { return m_colorBehavior; } | 86 const ColorBehavior& getColorBehavior() const { return m_colorBehavior; } |
| 87 | 87 |
| 88 bool contextDisabled() const { return m_disabledState; } | 88 bool contextDisabled() const { return m_disabledState; } |
| 89 | 89 |
| 90 // ---------- State management methods ----------------- | 90 // ---------- State management methods ----------------- |
| 91 void save(); | 91 void save(); |
| 92 void restore(); | 92 void restore(); |
| 93 | 93 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 void fillRect(const FloatRect&, | 175 void fillRect(const FloatRect&, |
| 176 const Color&, | 176 const Color&, |
| 177 SkBlendMode = SkBlendMode::kSrcOver); | 177 SkBlendMode = SkBlendMode::kSrcOver); |
| 178 void fillRoundedRect(const FloatRoundedRect&, const Color&); | 178 void fillRoundedRect(const FloatRoundedRect&, const Color&); |
| 179 void fillDRRect(const FloatRoundedRect&, | 179 void fillDRRect(const FloatRoundedRect&, |
| 180 const FloatRoundedRect&, | 180 const FloatRoundedRect&, |
| 181 const Color&); | 181 const Color&); |
| 182 | 182 |
| 183 void strokeRect(const FloatRect&, float lineWidth); | 183 void strokeRect(const FloatRect&, float lineWidth); |
| 184 | 184 |
| 185 void drawPicture(const SkPicture*); | 185 void drawPicture(const PaintRecord*); |
| 186 void compositePicture(sk_sp<SkPicture>, | 186 void compositePicture(sk_sp<PaintRecord>, |
| 187 const FloatRect& dest, | 187 const FloatRect& dest, |
| 188 const FloatRect& src, | 188 const FloatRect& src, |
| 189 SkBlendMode); | 189 SkBlendMode); |
| 190 | 190 |
| 191 void drawImage(Image*, | 191 void drawImage(Image*, |
| 192 const FloatRect& destRect, | 192 const FloatRect& destRect, |
| 193 const FloatRect* srcRect = nullptr, | 193 const FloatRect* srcRect = nullptr, |
| 194 SkBlendMode = SkBlendMode::kSrcOver, | 194 SkBlendMode = SkBlendMode::kSrcOver, |
| 195 RespectImageOrientationEnum = DoNotRespectImageOrientation); | 195 RespectImageOrientationEnum = DoNotRespectImageOrientation); |
| 196 void drawImageRRect( | 196 void drawImageRRect( |
| (...skipping 12 matching lines...) Expand all Loading... |
| 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 SkBlendMode = SkBlendMode::kSrcOver); | 214 SkBlendMode = SkBlendMode::kSrcOver); |
| 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 | 217 // Also drawLine(const IntPoint& point1, const IntPoint& point2) and |
| 218 // fillRoundedRect(). | 218 // fillRoundedRect(). |
| 219 void drawOval(const SkRect&, const SkPaint&); | 219 void drawOval(const SkRect&, const PaintFlags&); |
| 220 void drawPath(const SkPath&, const SkPaint&); | 220 void drawPath(const SkPath&, const PaintFlags&); |
| 221 void drawRect(const SkRect&, const SkPaint&); | 221 void drawRect(const SkRect&, const PaintFlags&); |
| 222 void drawRRect(const SkRRect&, const SkPaint&); | 222 void drawRRect(const SkRRect&, const PaintFlags&); |
| 223 | 223 |
| 224 void clip(const IntRect& rect) { clipRect(rect); } | 224 void clip(const IntRect& rect) { clipRect(rect); } |
| 225 void clip(const FloatRect& rect) { clipRect(rect); } | 225 void clip(const FloatRect& rect) { clipRect(rect); } |
| 226 void clipRoundedRect(const FloatRoundedRect&, | 226 void clipRoundedRect(const FloatRoundedRect&, |
| 227 SkClipOp = SkClipOp::kIntersect, | 227 SkClipOp = SkClipOp::kIntersect, |
| 228 AntiAliasingMode = AntiAliased); | 228 AntiAliasingMode = AntiAliased); |
| 229 void clipOut(const IntRect& rect) { | 229 void clipOut(const IntRect& rect) { |
| 230 clipRect(rect, NotAntiAliased, SkClipOp::kDifference); | 230 clipRect(rect, NotAntiAliased, SkClipOp::kDifference); |
| 231 } | 231 } |
| 232 void clipOut(const FloatRect& rect) { | 232 void clipOut(const FloatRect& rect) { |
| 233 clipRect(rect, NotAntiAliased, SkClipOp::kDifference); | 233 clipRect(rect, NotAntiAliased, SkClipOp::kDifference); |
| 234 } | 234 } |
| 235 void clipOut(const Path&); | 235 void clipOut(const Path&); |
| 236 void clipOutRoundedRect(const FloatRoundedRect&); | 236 void clipOutRoundedRect(const FloatRoundedRect&); |
| 237 void clipPath(const SkPath&, | 237 void clipPath(const SkPath&, |
| 238 AntiAliasingMode = NotAntiAliased, | 238 AntiAliasingMode = NotAntiAliased, |
| 239 SkClipOp = SkClipOp::kIntersect); | 239 SkClipOp = SkClipOp::kIntersect); |
| 240 void clipRect(const SkRect&, | 240 void clipRect(const SkRect&, |
| 241 AntiAliasingMode = NotAntiAliased, | 241 AntiAliasingMode = NotAntiAliased, |
| 242 SkClipOp = SkClipOp::kIntersect); | 242 SkClipOp = SkClipOp::kIntersect); |
| 243 | 243 |
| 244 void drawText(const Font&, const TextRunPaintInfo&, const FloatPoint&); | 244 void drawText(const Font&, const TextRunPaintInfo&, const FloatPoint&); |
| 245 void drawText(const Font&, | 245 void drawText(const Font&, |
| 246 const TextRunPaintInfo&, | 246 const TextRunPaintInfo&, |
| 247 const FloatPoint&, | 247 const FloatPoint&, |
| 248 const SkPaint&); | 248 const PaintFlags&); |
| 249 void drawEmphasisMarks(const Font&, | 249 void drawEmphasisMarks(const Font&, |
| 250 const TextRunPaintInfo&, | 250 const TextRunPaintInfo&, |
| 251 const AtomicString& mark, | 251 const AtomicString& mark, |
| 252 const FloatPoint&); | 252 const FloatPoint&); |
| 253 void drawBidiText( | 253 void drawBidiText( |
| 254 const Font&, | 254 const Font&, |
| 255 const TextRunPaintInfo&, | 255 const TextRunPaintInfo&, |
| 256 const FloatPoint&, | 256 const FloatPoint&, |
| 257 Font::CustomFontNotReadyAction = Font::DoNotPaintIfFontNotReady); | 257 Font::CustomFontNotReadyAction = Font::DoNotPaintIfFontNotReady); |
| 258 void drawHighlightForText(const Font&, | 258 void drawHighlightForText(const Font&, |
| (...skipping 24 matching lines...) Expand all Loading... |
| 283 void endLayer(); | 283 void endLayer(); |
| 284 | 284 |
| 285 // Instead of being dispatched to the active canvas, draw commands following | 285 // Instead of being dispatched to the active canvas, draw commands following |
| 286 // beginRecording() are stored in a display list that can be replayed at a | 286 // beginRecording() are stored in a display list that can be replayed at a |
| 287 // later time. Pass in the bounding rectangle for the content in the list. | 287 // later time. Pass in the bounding rectangle for the content in the list. |
| 288 void beginRecording(const FloatRect&); | 288 void beginRecording(const FloatRect&); |
| 289 | 289 |
| 290 // Returns a picture with any recorded draw commands since the prerequisite | 290 // Returns a picture with any recorded draw commands since the prerequisite |
| 291 // call to beginRecording(). The picture is guaranteed to be non-null (but | 291 // call to beginRecording(). The picture is guaranteed to be non-null (but |
| 292 // not necessarily non-empty), even when the context is disabled. | 292 // not necessarily non-empty), even when the context is disabled. |
| 293 sk_sp<SkPicture> endRecording(); | 293 sk_sp<PaintRecord> endRecording(); |
| 294 | 294 |
| 295 void setShadow(const FloatSize& offset, | 295 void setShadow(const FloatSize& offset, |
| 296 float blur, | 296 float blur, |
| 297 const Color&, | 297 const Color&, |
| 298 DrawLooperBuilder::ShadowTransformMode = | 298 DrawLooperBuilder::ShadowTransformMode = |
| 299 DrawLooperBuilder::ShadowRespectsTransforms, | 299 DrawLooperBuilder::ShadowRespectsTransforms, |
| 300 DrawLooperBuilder::ShadowAlphaMode = | 300 DrawLooperBuilder::ShadowAlphaMode = |
| 301 DrawLooperBuilder::ShadowRespectsAlpha, | 301 DrawLooperBuilder::ShadowRespectsAlpha, |
| 302 ShadowMode = DrawShadowAndForeground); | 302 ShadowMode = DrawShadowAndForeground); |
| 303 | 303 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 317 LeftEdge = 1 << 4 | 317 LeftEdge = 1 << 4 |
| 318 }; | 318 }; |
| 319 typedef unsigned Edges; | 319 typedef unsigned Edges; |
| 320 void drawInnerShadow(const FloatRoundedRect&, | 320 void drawInnerShadow(const FloatRoundedRect&, |
| 321 const Color& shadowColor, | 321 const Color& shadowColor, |
| 322 const FloatSize& shadowOffset, | 322 const FloatSize& shadowOffset, |
| 323 float shadowBlur, | 323 float shadowBlur, |
| 324 float shadowSpread, | 324 float shadowSpread, |
| 325 Edges clippedEdges = NoEdge); | 325 Edges clippedEdges = NoEdge); |
| 326 | 326 |
| 327 const SkPaint& fillPaint() const { return immutableState()->fillPaint(); } | 327 const PaintFlags& fillPaint() const { return immutableState()->fillPaint(); } |
| 328 const SkPaint& strokePaint() const { return immutableState()->strokePaint(); } | 328 const PaintFlags& strokePaint() const { |
| 329 return immutableState()->strokePaint(); |
| 330 } |
| 329 | 331 |
| 330 // ---------- Transformation methods ----------------- | 332 // ---------- Transformation methods ----------------- |
| 331 void concatCTM(const AffineTransform&); | 333 void concatCTM(const AffineTransform&); |
| 332 | 334 |
| 333 void scale(float x, float y); | 335 void scale(float x, float y); |
| 334 void rotate(float angleInRadians); | 336 void rotate(float angleInRadians); |
| 335 void translate(float x, float y); | 337 void translate(float x, float y); |
| 336 // ---------- End transformation methods ----------------- | 338 // ---------- End transformation methods ----------------- |
| 337 | 339 |
| 338 SkFilterQuality computeFilterQuality(Image*, | 340 SkFilterQuality computeFilterQuality(Image*, |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 static inline int focusRingOffset(int offset) { return offset + 2; } | 386 static inline int focusRingOffset(int offset) { return offset + 2; } |
| 385 #else | 387 #else |
| 386 static inline int focusRingOffset(int offset) { return 0; } | 388 static inline int focusRingOffset(int offset) { return 0; } |
| 387 static SkPMColor lineColors(int); | 389 static SkPMColor lineColors(int); |
| 388 static SkPMColor antiColors1(int); | 390 static SkPMColor antiColors1(int); |
| 389 static SkPMColor antiColors2(int); | 391 static SkPMColor antiColors2(int); |
| 390 static void draw1xMarker(SkBitmap*, int); | 392 static void draw1xMarker(SkBitmap*, int); |
| 391 static void draw2xMarker(SkBitmap*, int); | 393 static void draw2xMarker(SkBitmap*, int); |
| 392 #endif | 394 #endif |
| 393 | 395 |
| 394 void saveLayer(const SkRect* bounds, const SkPaint*); | 396 void saveLayer(const SkRect* bounds, const PaintFlags*); |
| 395 void restoreLayer(); | 397 void restoreLayer(); |
| 396 | 398 |
| 397 // Helpers for drawing a focus ring (drawFocusRing) | 399 // Helpers for drawing a focus ring (drawFocusRing) |
| 398 void drawFocusRingPath(const SkPath&, const Color&, float width); | 400 void drawFocusRingPath(const SkPath&, const Color&, float width); |
| 399 void drawFocusRingRect(const SkRect&, const Color&, float width); | 401 void drawFocusRingRect(const SkRect&, const Color&, float width); |
| 400 | 402 |
| 401 // SkCanvas wrappers. | 403 // SkCanvas wrappers. |
| 402 void clipRRect(const SkRRect&, | 404 void clipRRect(const SkRRect&, |
| 403 AntiAliasingMode = NotAntiAliased, | 405 AntiAliasingMode = NotAntiAliased, |
| 404 SkClipOp = SkClipOp::kIntersect); | 406 SkClipOp = SkClipOp::kIntersect); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 424 } | 426 } |
| 425 } | 427 } |
| 426 | 428 |
| 427 void fillRectWithRoundedHole(const FloatRect&, | 429 void fillRectWithRoundedHole(const FloatRect&, |
| 428 const FloatRoundedRect& roundedHoleRect, | 430 const FloatRoundedRect& roundedHoleRect, |
| 429 const Color&); | 431 const Color&); |
| 430 | 432 |
| 431 const SkMetaData& metaData() const { return m_metaData; } | 433 const SkMetaData& metaData() const { return m_metaData; } |
| 432 | 434 |
| 433 // null indicates painting is contextDisabled. Never delete this object. | 435 // null indicates painting is contextDisabled. Never delete this object. |
| 434 SkCanvas* m_canvas; | 436 PaintCanvas* m_canvas; |
| 435 | 437 |
| 436 PaintController& m_paintController; | 438 PaintController& m_paintController; |
| 437 | 439 |
| 438 // Paint states stack. The state controls the appearance of drawn content, so | 440 // Paint states stack. The state controls the appearance of drawn content, so |
| 439 // this stack enables local drawing state changes with save()/restore() calls. | 441 // this stack enables local drawing state changes with save()/restore() calls. |
| 440 // We do not delete from this stack to avoid memory churn. | 442 // We do not delete from this stack to avoid memory churn. |
| 441 Vector<std::unique_ptr<GraphicsContextState>> m_paintStateStack; | 443 Vector<std::unique_ptr<GraphicsContextState>> m_paintStateStack; |
| 442 | 444 |
| 443 // Current index on the stack. May not be the last thing on the stack. | 445 // Current index on the stack. May not be the last thing on the stack. |
| 444 unsigned m_paintStateIndex; | 446 unsigned m_paintStateIndex; |
| 445 | 447 |
| 446 // Raw pointer to the current state. | 448 // Raw pointer to the current state. |
| 447 GraphicsContextState* m_paintState; | 449 GraphicsContextState* m_paintState; |
| 448 | 450 |
| 449 SkPictureRecorder m_pictureRecorder; | 451 PaintRecorder m_pictureRecorder; |
| 450 | 452 |
| 451 SkMetaData m_metaData; | 453 SkMetaData m_metaData; |
| 452 | 454 |
| 453 const ColorBehavior m_colorBehavior; | 455 const ColorBehavior m_colorBehavior; |
| 454 | 456 |
| 455 #if DCHECK_IS_ON() | 457 #if DCHECK_IS_ON() |
| 456 int m_layerCount; | 458 int m_layerCount; |
| 457 bool m_disableDestructionChecks; | 459 bool m_disableDestructionChecks; |
| 458 bool m_inDrawingRecorder; | 460 bool m_inDrawingRecorder; |
| 459 #endif | 461 #endif |
| 460 | 462 |
| 461 const DisabledMode m_disabledState; | 463 const DisabledMode m_disabledState; |
| 462 | 464 |
| 463 float m_deviceScaleFactor; | 465 float m_deviceScaleFactor; |
| 464 | 466 |
| 465 unsigned m_printing : 1; | 467 unsigned m_printing : 1; |
| 466 unsigned m_hasMetaData : 1; | 468 unsigned m_hasMetaData : 1; |
| 467 }; | 469 }; |
| 468 | 470 |
| 469 } // namespace blink | 471 } // namespace blink |
| 470 | 472 |
| 471 #endif // GraphicsContext_h | 473 #endif // GraphicsContext_h |
| OLD | NEW |