Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(319)

Side by Side Diff: Source/core/platform/graphics/GraphicsContextState.h

Issue 17448009: Use skia::RefPtr to avoid having to manually refcount GraphicsContextState::m_looper. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/core/platform/graphics/GraphicsContext.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 16 matching lines...) Expand all
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" 32 #include "core/platform/graphics/Gradient.h"
33 #include "core/platform/graphics/GraphicsTypes.h" 33 #include "core/platform/graphics/GraphicsTypes.h"
34 #include "core/platform/graphics/Path.h" 34 #include "core/platform/graphics/Path.h"
35 #include "core/platform/graphics/Pattern.h" 35 #include "core/platform/graphics/Pattern.h"
36 #include "core/platform/graphics/StrokeData.h" 36 #include "core/platform/graphics/StrokeData.h"
37
38 #include "third_party/skia/include/core/SkColorPriv.h" 37 #include "third_party/skia/include/core/SkColorPriv.h"
39 #include "third_party/skia/include/core/SkDrawLooper.h" 38 #include "third_party/skia/include/core/SkDrawLooper.h"
40 #include "third_party/skia/include/effects/SkDashPathEffect.h" 39 #include "third_party/skia/include/effects/SkDashPathEffect.h"
41
42 #include "wtf/PassOwnPtr.h" 40 #include "wtf/PassOwnPtr.h"
41 #include "wtf/RefPtr.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:
50 ~GraphicsContextState()
51 {
52 SkSafeUnref(m_looper);
53 }
54
55 private: 48 private:
56 friend class GraphicsContext; 49 friend class GraphicsContext;
57 50
58 GraphicsContextState() 51 GraphicsContextState()
59 : m_fillColor(Color::black) 52 : m_fillColor(Color::black)
60 , m_fillRule(RULE_NONZERO) 53 , m_fillRule(RULE_NONZERO)
61 , m_looper(0)
62 , m_textDrawingMode(TextModeFill) 54 , m_textDrawingMode(TextModeFill)
63 , m_alpha(1) 55 , m_alpha(1)
64 , m_xferMode(SkXfermode::kSrcOver_Mode) 56 , m_xferMode(SkXfermode::kSrcOver_Mode)
65 , m_compositeOperator(CompositeSourceOver) 57 , m_compositeOperator(CompositeSourceOver)
66 , m_blendMode(BlendModeNormal) 58 , m_blendMode(BlendModeNormal)
67 , m_clip(SkRect::MakeEmpty()) 59 , m_clip(SkRect::MakeEmpty())
68 #if USE(LOW_QUALITY_IMAGE_INTERPOLATION) 60 #if USE(LOW_QUALITY_IMAGE_INTERPOLATION)
69 , m_interpolationQuality(InterpolationLow) 61 , m_interpolationQuality(InterpolationLow)
70 #else 62 #else
71 , m_interpolationQuality(InterpolationHigh) 63 , m_interpolationQuality(InterpolationHigh)
72 #endif 64 #endif
73 , m_shouldAntialias(true) 65 , m_shouldAntialias(true)
74 , m_shouldSmoothFonts(true) 66 , m_shouldSmoothFonts(true)
75 { 67 {
76 } 68 }
77 69
78 GraphicsContextState(const GraphicsContextState& other) 70 GraphicsContextState(const GraphicsContextState& other)
79 : m_strokeData(other.m_strokeData) 71 : m_strokeData(other.m_strokeData)
80 , m_fillColor(other.m_fillColor) 72 , m_fillColor(other.m_fillColor)
81 , m_fillRule(other.m_fillRule) 73 , m_fillRule(other.m_fillRule)
82 , m_fillGradient(other.m_fillGradient) 74 , m_fillGradient(other.m_fillGradient)
83 , m_fillPattern(other.m_fillPattern) 75 , m_fillPattern(other.m_fillPattern)
84 , m_looper(other.m_looper) 76 , m_looper(other.m_looper)
85 , m_textDrawingMode(other.m_textDrawingMode) 77 , m_textDrawingMode(other.m_textDrawingMode)
86 , m_alpha(other.m_alpha) 78 , m_alpha(other.m_alpha)
87 , m_xferMode(other.m_xferMode) 79 , m_xferMode(other.m_xferMode)
88 , m_compositeOperator(other.m_compositeOperator) 80 , m_compositeOperator(other.m_compositeOperator)
89 , m_blendMode(other.m_blendMode) 81 , m_blendMode(other.m_blendMode)
90 , m_imageBufferClip(other.m_imageBufferClip)
91 , m_clip(other.m_clip) 82 , m_clip(other.m_clip)
92 , m_interpolationQuality(other.m_interpolationQuality) 83 , m_interpolationQuality(other.m_interpolationQuality)
93 , m_shouldAntialias(other.m_shouldAntialias) 84 , m_shouldAntialias(other.m_shouldAntialias)
94 , m_shouldSmoothFonts(other.m_shouldSmoothFonts) 85 , m_shouldSmoothFonts(other.m_shouldSmoothFonts)
95 { 86 {
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 } 87 }
103 88
104 // Helper function for applying the state's alpha value to the given input 89 // Helper function for applying the state's alpha value to the given input
105 // color to produce a new output color. 90 // color to produce a new output color.
106 SkColor applyAlpha(SkColor c) const 91 SkColor applyAlpha(SkColor c) const
107 { 92 {
108 int s = roundf(m_alpha * 256); 93 int s = roundf(m_alpha * 256);
109 if (s >= 256) 94 if (s >= 256)
110 return c; 95 return c;
111 if (s < 0) 96 if (s < 0)
(...skipping 12 matching lines...) Expand all
124 // Stroke. 109 // Stroke.
125 StrokeData m_strokeData; 110 StrokeData m_strokeData;
126 111
127 // Fill. 112 // Fill.
128 Color m_fillColor; 113 Color m_fillColor;
129 WindRule m_fillRule; 114 WindRule m_fillRule;
130 RefPtr<Gradient> m_fillGradient; 115 RefPtr<Gradient> m_fillGradient;
131 RefPtr<Pattern> m_fillPattern; 116 RefPtr<Pattern> m_fillPattern;
132 117
133 // Shadow. (This will need tweaking if we use draw loopers for other things. ) 118 // Shadow. (This will need tweaking if we use draw loopers for other things. )
134 SkDrawLooper* m_looper; 119 RefPtr<SkDrawLooper> m_looper;
135 120
136 // Text. (See TextModeFill & friends.) 121 // Text. (See TextModeFill & friends.)
137 TextDrawingModeFlags m_textDrawingMode; 122 TextDrawingModeFlags m_textDrawingMode;
138 123
139 // Common shader state. 124 // Common shader state.
140 float m_alpha; 125 float m_alpha;
141 SkXfermode::Mode m_xferMode; 126 SkXfermode::Mode m_xferMode;
142 127
143 // Compositing control, for the CSS and Canvas compositing spec. 128 // Compositing control, for the CSS and Canvas compositing spec.
144 CompositeOperator m_compositeOperator; 129 CompositeOperator m_compositeOperator;
145 BlendMode m_blendMode; 130 BlendMode m_blendMode;
146 131
147 // If non-empty, the current State is clipped to this image. 132 // If non-empty, the current State is clipped to this image.
148 SkBitmap m_imageBufferClip; 133 SkBitmap m_imageBufferClip;
149 134
150 // If m_imageBufferClip is non-empty, this is the region the image is clippe d to. 135 // If m_imageBufferClip is non-empty, this is the region the image is clippe d to.
151 SkRect m_clip; 136 SkRect m_clip;
152 137
153 // Image interpolation control. 138 // Image interpolation control.
154 InterpolationQuality m_interpolationQuality; 139 InterpolationQuality m_interpolationQuality;
155 140
156 bool m_shouldAntialias : 1; 141 bool m_shouldAntialias : 1;
157 bool m_shouldSmoothFonts : 1; 142 bool m_shouldSmoothFonts : 1;
158 }; 143 };
159 144
160 } // namespace WebCore 145 } // namespace WebCore
161 146
162 #endif // GraphicsContextState_h 147 #endif // GraphicsContextState_h
163 148
OLDNEW
« no previous file with comments | « Source/core/platform/graphics/GraphicsContext.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698