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