| OLD | NEW |
| 1 // Copyright (C) 2013 Google Inc. All rights reserved. | 1 // Copyright (C) 2013 Google Inc. All rights reserved. |
| 2 // | 2 // |
| 3 // Redistribution and use in source and binary forms, with or without | 3 // Redistribution and use in source and binary forms, with or without |
| 4 // modification, are permitted provided that the following conditions are | 4 // modification, are permitted provided that the following conditions are |
| 5 // met: | 5 // met: |
| 6 // | 6 // |
| 7 // * Redistributions of source code must retain the above copyright | 7 // * Redistributions of source code must retain the above copyright |
| 8 // notice, this list of conditions and the following disclaimer. | 8 // notice, this list of conditions and the following disclaimer. |
| 9 // * Redistributions in binary form must reproduce the above | 9 // * Redistributions in binary form must reproduce the above |
| 10 // copyright notice, this list of conditions and the following disclaimer | 10 // copyright notice, this list of conditions and the following disclaimer |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | 28 |
| 29 #ifndef GraphicsContextState_h | 29 #ifndef GraphicsContextState_h |
| 30 #define GraphicsContextState_h | 30 #define GraphicsContextState_h |
| 31 | 31 |
| 32 #include "core/platform/graphics/Gradient.h" | |
| 33 #include "core/platform/graphics/GraphicsTypes.h" | 32 #include "core/platform/graphics/GraphicsTypes.h" |
| 34 #include "core/platform/graphics/Path.h" | |
| 35 #include "core/platform/graphics/Pattern.h" | |
| 36 #include "core/platform/graphics/StrokeData.h" | 33 #include "core/platform/graphics/StrokeData.h" |
| 34 #include "core/platform/graphics/WindRule.h" |
| 35 #include "third_party/skia/include/core/SkBitmap.h" |
| 36 #include "third_party/skia/include/core/SkRect.h" |
| 37 #include "third_party/skia/include/core/SkXfermode.h" |
| 38 #include "wtf/PassOwnPtr.h" |
| 39 #include "wtf/RefPtr.h" |
| 37 | 40 |
| 38 #include "third_party/skia/include/core/SkColorPriv.h" | 41 class SkDrawLooper; |
| 39 #include "third_party/skia/include/core/SkDrawLooper.h" | |
| 40 #include "third_party/skia/include/effects/SkDashPathEffect.h" | |
| 41 | |
| 42 #include "wtf/PassOwnPtr.h" | |
| 43 | 42 |
| 44 namespace WebCore { | 43 namespace WebCore { |
| 45 | 44 |
| 46 // Encapsulates the state information we store for each pushed graphics state. | 45 // Encapsulates the state information we store for each pushed graphics state. |
| 47 // Only GraphicsContext can use this class. | 46 // Only GraphicsContext can use this class. |
| 48 class GraphicsContextState { | 47 class GraphicsContextState { |
| 49 public: | 48 public: |
| 50 ~GraphicsContextState() | 49 ~GraphicsContextState(); |
| 51 { | |
| 52 SkSafeUnref(m_looper); | |
| 53 } | |
| 54 | 50 |
| 55 private: | 51 private: |
| 56 friend class GraphicsContext; | 52 friend class GraphicsContext; |
| 57 | 53 |
| 58 GraphicsContextState() | 54 GraphicsContextState(); |
| 59 : m_fillColor(Color::black) | 55 GraphicsContextState(const GraphicsContextState& other); |
| 60 , m_fillRule(RULE_NONZERO) | |
| 61 , m_looper(0) | |
| 62 , m_textDrawingMode(TextModeFill) | |
| 63 , m_alpha(1) | |
| 64 , m_xferMode(SkXfermode::kSrcOver_Mode) | |
| 65 , m_compositeOperator(CompositeSourceOver) | |
| 66 , m_blendMode(BlendModeNormal) | |
| 67 , m_clip(SkRect::MakeEmpty()) | |
| 68 #if USE(LOW_QUALITY_IMAGE_INTERPOLATION) | |
| 69 , m_interpolationQuality(InterpolationLow) | |
| 70 #else | |
| 71 , m_interpolationQuality(InterpolationHigh) | |
| 72 #endif | |
| 73 , m_shouldAntialias(true) | |
| 74 , m_shouldSmoothFonts(true) | |
| 75 { | |
| 76 } | |
| 77 | |
| 78 GraphicsContextState(const GraphicsContextState& other) | |
| 79 : m_strokeData(other.m_strokeData) | |
| 80 , m_fillColor(other.m_fillColor) | |
| 81 , m_fillRule(other.m_fillRule) | |
| 82 , m_fillGradient(other.m_fillGradient) | |
| 83 , m_fillPattern(other.m_fillPattern) | |
| 84 , m_looper(other.m_looper) | |
| 85 , m_textDrawingMode(other.m_textDrawingMode) | |
| 86 , m_alpha(other.m_alpha) | |
| 87 , m_xferMode(other.m_xferMode) | |
| 88 , m_compositeOperator(other.m_compositeOperator) | |
| 89 , m_blendMode(other.m_blendMode) | |
| 90 , m_imageBufferClip(other.m_imageBufferClip) | |
| 91 , m_clip(other.m_clip) | |
| 92 , m_interpolationQuality(other.m_interpolationQuality) | |
| 93 , m_shouldAntialias(other.m_shouldAntialias) | |
| 94 , m_shouldSmoothFonts(other.m_shouldSmoothFonts) | |
| 95 { | |
| 96 // Up the ref count of these. SkSafeRef does nothing if its argument is
0. | |
| 97 SkSafeRef(m_looper); | |
| 98 | |
| 99 // The clip image only needs to be applied once. Reset the image so that
we | |
| 100 // don't attempt to clip multiple times. | |
| 101 m_imageBufferClip.reset(); | |
| 102 } | |
| 103 | |
| 104 // Helper function for applying the state's alpha value to the given input | |
| 105 // color to produce a new output color. | |
| 106 SkColor applyAlpha(SkColor c) const | |
| 107 { | |
| 108 int s = roundf(m_alpha * 256); | |
| 109 if (s >= 256) | |
| 110 return c; | |
| 111 if (s < 0) | |
| 112 return 0; | |
| 113 | |
| 114 int a = SkAlphaMul(SkColorGetA(c), s); | |
| 115 return (c & 0x00FFFFFF) | (a << 24); | |
| 116 } | |
| 117 | 56 |
| 118 // Returns a new State with all of this object's inherited properties copied
. | 57 // Returns a new State with all of this object's inherited properties copied
. |
| 119 PassOwnPtr<GraphicsContextState> clone() { return adoptPtr(new GraphicsConte
xtState(*this)); } | 58 PassOwnPtr<GraphicsContextState> clone() { return adoptPtr(new GraphicsConte
xtState(*this)); } |
| 120 | 59 |
| 121 // Not supported. No implementations. | 60 // Not supported. No implementations. |
| 122 void operator=(const GraphicsContextState&); | 61 void operator=(const GraphicsContextState&); |
| 123 | 62 |
| 124 // Stroke. | 63 // Stroke. |
| 125 StrokeData m_strokeData; | 64 StrokeData m_strokeData; |
| 126 | 65 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 154 InterpolationQuality m_interpolationQuality; | 93 InterpolationQuality m_interpolationQuality; |
| 155 | 94 |
| 156 bool m_shouldAntialias : 1; | 95 bool m_shouldAntialias : 1; |
| 157 bool m_shouldSmoothFonts : 1; | 96 bool m_shouldSmoothFonts : 1; |
| 158 }; | 97 }; |
| 159 | 98 |
| 160 } // namespace WebCore | 99 } // namespace WebCore |
| 161 | 100 |
| 162 #endif // GraphicsContextState_h | 101 #endif // GraphicsContextState_h |
| 163 | 102 |
| OLD | NEW |