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

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

Issue 206493002: Minor Gradient cleanup. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « Source/platform/graphics/Gradient.h ('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 /* 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 , m_stopsSorted(false) 61 , m_stopsSorted(false)
62 , m_drawInPMColorSpace(false) 62 , m_drawInPMColorSpace(false)
63 , m_spreadMethod(SpreadMethodPad) 63 , m_spreadMethod(SpreadMethodPad)
64 { 64 {
65 } 65 }
66 66
67 Gradient::~Gradient() 67 Gradient::~Gradient()
68 { 68 {
69 } 69 }
70 70
71 void Gradient::addColorStop(float value, const Color& color)
72 {
73 m_stops.append(ColorStop(value, color));
74
75 m_stopsSorted = false;
76 m_gradient.clear();
77 }
78
79 void Gradient::addColorStop(const Gradient::ColorStop& stop)
80 {
81 m_stops.append(stop);
82
83 m_stopsSorted = false;
84 m_gradient.clear();
85 }
86
87 static inline bool compareStops(const Gradient::ColorStop& a, const Gradient::Co lorStop& b) 71 static inline bool compareStops(const Gradient::ColorStop& a, const Gradient::Co lorStop& b)
88 { 72 {
89 return a.stop < b.stop; 73 return a.stop < b.stop;
90 } 74 }
91 75
76 void Gradient::addColorStop(const Gradient::ColorStop& stop)
77 {
78 if (m_stops.isEmpty()) {
79 m_stopsSorted = true;
80 } else {
81 m_stopsSorted = m_stopsSorted && compareStops(m_stops.last(), stop);
82 }
83
84 m_stops.append(stop);
85 m_gradient.clear();
86 }
87
92 void Gradient::sortStopsIfNecessary() 88 void Gradient::sortStopsIfNecessary()
93 { 89 {
94 if (m_stopsSorted) 90 if (m_stopsSorted)
95 return; 91 return;
96 92
97 m_stopsSorted = true; 93 m_stopsSorted = true;
98 94
99 if (!m_stops.size()) 95 if (!m_stops.size())
100 return; 96 return;
101 97
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 if (!m_gradient) { 260 if (!m_gradient) {
265 // use last color, since our "geometry" was degenerate (e.g. radius==0) 261 // use last color, since our "geometry" was degenerate (e.g. radius==0)
266 m_gradient = adoptRef(new SkColorShader(colors[countUsed - 1])); 262 m_gradient = adoptRef(new SkColorShader(colors[countUsed - 1]));
267 } else { 263 } else {
268 m_gradient->setLocalMatrix(affineTransformToSkMatrix(m_gradientSpaceTran sformation)); 264 m_gradient->setLocalMatrix(affineTransformToSkMatrix(m_gradientSpaceTran sformation));
269 } 265 }
270 return m_gradient.get(); 266 return m_gradient.get();
271 } 267 }
272 268
273 } //namespace 269 } //namespace
OLDNEW
« no previous file with comments | « Source/platform/graphics/Gradient.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698