| 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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 FullyDisabled = 1 // Do absolutely minimal work to remove the cost of th
e context from performance tests. | 75 FullyDisabled = 1 // Do absolutely minimal work to remove the cost of th
e context from performance tests. |
| 76 }; | 76 }; |
| 77 | 77 |
| 78 // A 0 canvas is allowed, but in such cases the context must only have canva
s | 78 // A 0 canvas is allowed, but in such cases the context must only have canva
s |
| 79 // related commands called when within a beginRecording/endRecording block. | 79 // related commands called when within a beginRecording/endRecording block. |
| 80 // Furthermore, save/restore calls must be balanced any time the canvas is 0
. | 80 // Furthermore, save/restore calls must be balanced any time the canvas is 0
. |
| 81 explicit GraphicsContext(SkCanvas*, DisabledMode = NothingDisabled); | 81 explicit GraphicsContext(SkCanvas*, DisabledMode = NothingDisabled); |
| 82 | 82 |
| 83 ~GraphicsContext(); | 83 ~GraphicsContext(); |
| 84 | 84 |
| 85 // Returns the canvas used for painting. Must not be called if painting is d
isabled. | 85 SkCanvas* canvas() { return m_canvas; } |
| 86 // Accessing the backing canvas this way flushes all queued save ops, | 86 const SkCanvas* canvas() const { return m_canvas; } |
| 87 // so it should be avoided. Use the corresponding draw/matrix/clip methods i
nstead. | |
| 88 SkCanvas* canvas() | |
| 89 { | |
| 90 // Flush any pending saves. | |
| 91 realizeCanvasSave(); | |
| 92 | |
| 93 return m_canvas; | |
| 94 } | |
| 95 const SkCanvas* canvas() const | |
| 96 { | |
| 97 return m_canvas; | |
| 98 } | |
| 99 | 87 |
| 100 void resetCanvas(SkCanvas*); | 88 void resetCanvas(SkCanvas*); |
| 101 | 89 |
| 102 bool contextDisabled() const { return m_disabledState; } | 90 bool contextDisabled() const { return m_disabledState; } |
| 103 | 91 |
| 104 // ---------- State management methods ----------------- | 92 // ---------- State management methods ----------------- |
| 105 void save(); | 93 void save(); |
| 106 void restore(); | 94 void restore(); |
| 107 unsigned saveCount() { return m_canvasStateStack.size(); } | 95 |
| 108 #if ENABLE(ASSERT) | 96 #if ENABLE(ASSERT) |
| 97 unsigned saveCount() const; |
| 109 void disableDestructionChecks() { m_disableDestructionChecks = true; } | 98 void disableDestructionChecks() { m_disableDestructionChecks = true; } |
| 110 #endif | 99 #endif |
| 111 | 100 |
| 112 void saveLayer(const SkRect* bounds, const SkPaint*); | 101 void saveLayer(const SkRect* bounds, const SkPaint*); |
| 113 void restoreLayer(); | 102 void restoreLayer(); |
| 114 | 103 |
| 115 bool hasStroke() const { return strokeStyle() != NoStroke && strokeThickness
() > 0; } | 104 bool hasStroke() const { return strokeStyle() != NoStroke && strokeThickness
() > 0; } |
| 116 | 105 |
| 117 float strokeThickness() const { return immutableState()->strokeData().thickn
ess(); } | 106 float strokeThickness() const { return immutableState()->strokeData().thickn
ess(); } |
| 118 void setStrokeThickness(float thickness) { mutableState()->setStrokeThicknes
s(thickness); } | 107 void setStrokeThickness(float thickness) { mutableState()->setStrokeThicknes
s(thickness); } |
| (...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 471 m_paintStateStack.append(GraphicsContextState::createAndCopy(*m_
paintState)); | 460 m_paintStateStack.append(GraphicsContextState::createAndCopy(*m_
paintState)); |
| 472 m_paintState = m_paintStateStack[m_paintStateIndex].get(); | 461 m_paintState = m_paintStateStack[m_paintStateIndex].get(); |
| 473 } else { | 462 } else { |
| 474 GraphicsContextState* priorPaintState = m_paintState; | 463 GraphicsContextState* priorPaintState = m_paintState; |
| 475 m_paintState = m_paintStateStack[m_paintStateIndex].get(); | 464 m_paintState = m_paintStateStack[m_paintStateIndex].get(); |
| 476 m_paintState->copy(*priorPaintState); | 465 m_paintState->copy(*priorPaintState); |
| 477 } | 466 } |
| 478 } | 467 } |
| 479 } | 468 } |
| 480 | 469 |
| 481 // Apply deferred canvas state saves | |
| 482 void realizeCanvasSave() | |
| 483 { | |
| 484 if (!m_pendingCanvasSave || contextDisabled()) | |
| 485 return; | |
| 486 | |
| 487 ASSERT(m_canvas); // m_pendingCanvasSave should never be true when no ca
nvas. | |
| 488 m_canvas->save(); | |
| 489 m_pendingCanvasSave = false; | |
| 490 } | |
| 491 | |
| 492 void didDrawTextInRect(const SkRect& textRect); | 470 void didDrawTextInRect(const SkRect& textRect); |
| 493 | 471 |
| 494 void fillRectWithRoundedHole(const IntRect&, const RoundedRect& roundedHoleR
ect, const Color&); | 472 void fillRectWithRoundedHole(const IntRect&, const RoundedRect& roundedHoleR
ect, const Color&); |
| 495 | 473 |
| 496 bool isRecording() const; | 474 bool isRecording() const; |
| 497 | 475 |
| 498 // null indicates painting is contextDisabled. Never delete this object. | 476 // null indicates painting is contextDisabled. Never delete this object. |
| 499 SkCanvas* m_canvas; | 477 SkCanvas* m_canvas; |
| 500 | 478 |
| 501 // Paint states stack. Enables local drawing state change with save()/restor
e() calls. | 479 // Paint states stack. Enables local drawing state change with save()/restor
e() calls. |
| 502 // This state controls the appearance of drawn content. | 480 // This state controls the appearance of drawn content. |
| 503 // We do not delete from this stack to avoid memory churn. | 481 // We do not delete from this stack to avoid memory churn. |
| 504 Vector<OwnPtr<GraphicsContextState> > m_paintStateStack; | 482 Vector<OwnPtr<GraphicsContextState> > m_paintStateStack; |
| 505 // Current index on the stack. May not be the last thing on the stack. | 483 // Current index on the stack. May not be the last thing on the stack. |
| 506 unsigned m_paintStateIndex; | 484 unsigned m_paintStateIndex; |
| 507 // Raw pointer to the current state. | 485 // Raw pointer to the current state. |
| 508 GraphicsContextState* m_paintState; | 486 GraphicsContextState* m_paintState; |
| 509 | 487 |
| 510 // Currently pending save flags for Skia Canvas state. | |
| 511 // Canvas state includes the canavs, it's matrix and clips. Think of it as _
where_ | |
| 512 // the draw operations will happen. | |
| 513 struct CanvasSaveState; | |
| 514 Vector<CanvasSaveState> m_canvasStateStack; | |
| 515 bool m_pendingCanvasSave; | |
| 516 | |
| 517 AnnotationModeFlags m_annotationMode; | 488 AnnotationModeFlags m_annotationMode; |
| 518 | 489 |
| 519 struct RecordingState; | 490 struct RecordingState; |
| 520 Vector<RecordingState> m_recordingStateStack; | 491 Vector<RecordingState> m_recordingStateStack; |
| 521 | 492 |
| 522 #if ENABLE(ASSERT) | 493 #if ENABLE(ASSERT) |
| 523 unsigned m_annotationCount; | 494 unsigned m_annotationCount; |
| 524 unsigned m_layerCount; | 495 unsigned m_layerCount; |
| 525 bool m_disableDestructionChecks; | 496 bool m_disableDestructionChecks; |
| 526 #endif | 497 #endif |
| (...skipping 14 matching lines...) Expand all Loading... |
| 541 bool m_accelerated : 1; | 512 bool m_accelerated : 1; |
| 542 bool m_isCertainlyOpaque : 1; | 513 bool m_isCertainlyOpaque : 1; |
| 543 bool m_printing : 1; | 514 bool m_printing : 1; |
| 544 bool m_antialiasHairlineImages : 1; | 515 bool m_antialiasHairlineImages : 1; |
| 545 bool m_shouldSmoothFonts : 1; | 516 bool m_shouldSmoothFonts : 1; |
| 546 }; | 517 }; |
| 547 | 518 |
| 548 } // namespace blink | 519 } // namespace blink |
| 549 | 520 |
| 550 #endif // GraphicsContext_h | 521 #endif // GraphicsContext_h |
| OLD | NEW |