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

Side by Side Diff: third_party/WebKit/Source/platform/graphics/Gradient.cpp

Issue 2640983002: Rename paint data structures (Closed)
Patch Set: Rebase Created 3 years, 11 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006, 2007, 2008, 2010 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2007, 2008, 2010 Apple Inc. All rights reserved.
3 * Copyright (C) 2007 Alp Toker <alp@atoker.com> 3 * Copyright (C) 2007 Alp Toker <alp@atoker.com>
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 11 matching lines...) Expand all
22 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 22 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
23 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
28 #include "platform/graphics/Gradient.h" 28 #include "platform/graphics/Gradient.h"
29 29
30 #include "platform/geometry/FloatRect.h" 30 #include "platform/geometry/FloatRect.h"
31 #include "platform/graphics/GraphicsContext.h" 31 #include "platform/graphics/GraphicsContext.h"
32 #include "platform/graphics/paint/PaintShader.h"
32 #include "platform/graphics/skia/SkiaUtils.h" 33 #include "platform/graphics/skia/SkiaUtils.h"
33 #include "third_party/skia/include/core/SkColor.h" 34 #include "third_party/skia/include/core/SkColor.h"
34 #include "third_party/skia/include/core/SkMatrix.h" 35 #include "third_party/skia/include/core/SkMatrix.h"
35 #include "third_party/skia/include/core/SkShader.h" 36 #include "third_party/skia/include/core/SkShader.h"
36 #include "third_party/skia/include/effects/SkGradientShader.h" 37 #include "third_party/skia/include/effects/SkGradientShader.h"
37 #include <algorithm> 38 #include <algorithm>
38 39
39 typedef Vector<SkScalar, 8> ColorStopOffsetVector; 40 typedef Vector<SkScalar, 8> ColorStopOffsetVector;
40 typedef Vector<SkColor, 8> ColorStopColorVector; 41 typedef Vector<SkColor, 8> ColorStopColorVector;
41 42
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 } 170 }
170 171
171 // Copy the last stop to 1.0 if needed. See comment above about this float 172 // Copy the last stop to 1.0 if needed. See comment above about this float
172 // comparison. 173 // comparison.
173 if (count < 1 || (--stop)->stop < 1.0) { 174 if (count < 1 || (--stop)->stop < 1.0) {
174 pos[start + count] = WebCoreFloatToSkScalar(1.0); 175 pos[start + count] = WebCoreFloatToSkScalar(1.0);
175 colors[start + count] = colors[start + count - 1]; 176 colors[start + count] = colors[start + count - 1];
176 } 177 }
177 } 178 }
178 179
179 sk_sp<SkShader> Gradient::createShader(const SkMatrix& localMatrix) { 180 sk_sp<PaintShader> Gradient::createShader(const SkMatrix& localMatrix) {
180 sortStopsIfNecessary(); 181 sortStopsIfNecessary();
181 ASSERT(m_stopsSorted); 182 ASSERT(m_stopsSorted);
182 183
183 size_t countUsed = totalStopsNeeded(m_stops.data(), m_stops.size()); 184 size_t countUsed = totalStopsNeeded(m_stops.data(), m_stops.size());
184 ASSERT(countUsed >= 2); 185 ASSERT(countUsed >= 2);
185 ASSERT(countUsed >= m_stops.size()); 186 ASSERT(countUsed >= m_stops.size());
186 187
187 ColorStopOffsetVector pos(countUsed); 188 ColorStopOffsetVector pos(countUsed);
188 ColorStopColorVector colors(countUsed); 189 ColorStopColorVector colors(countUsed);
189 fillStops(m_stops.data(), m_stops.size(), pos, colors); 190 fillStops(m_stops.data(), m_stops.size(), pos, colors);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 shader = SkGradientShader::MakeLinear( 240 shader = SkGradientShader::MakeLinear(
240 pts, colors.data(), pos.data(), static_cast<int>(countUsed), tile, 241 pts, colors.data(), pos.data(), static_cast<int>(countUsed), tile,
241 shouldDrawInPMColorSpace, &localMatrix); 242 shouldDrawInPMColorSpace, &localMatrix);
242 } 243 }
243 244
244 if (!shader) { 245 if (!shader) {
245 // use last color, since our "geometry" was degenerate (e.g. radius==0) 246 // use last color, since our "geometry" was degenerate (e.g. radius==0)
246 shader = SkShader::MakeColorShader(colors[countUsed - 1]); 247 shader = SkShader::MakeColorShader(colors[countUsed - 1]);
247 } 248 }
248 249
249 return shader; 250 return WrapSkShader(shader);
250 } 251 }
251 252
252 void Gradient::applyToPaint(SkPaint& paint, const SkMatrix& localMatrix) { 253 void Gradient::applyToPaint(PaintFlags& paint, const SkMatrix& localMatrix) {
253 if (!m_cachedShader || localMatrix != m_cachedShader->getLocalMatrix()) 254 if (!m_cachedShader || localMatrix != m_cachedShader->getLocalMatrix())
254 m_cachedShader = createShader(localMatrix); 255 m_cachedShader = createShader(localMatrix);
255 256
256 paint.setShader(m_cachedShader); 257 paint.setShader(m_cachedShader);
257 258
258 // Legacy behavior: gradients are always dithered. 259 // Legacy behavior: gradients are always dithered.
259 paint.setDither(true); 260 paint.setDither(true);
260 } 261 }
261 262
262 } // namespace blink 263 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698