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

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

Issue 169283008: Maintain SkPaint in GraphicsContextState. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Ready for review. 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
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 21 matching lines...) Expand all
32 #include "platform/graphics/Color.h" 32 #include "platform/graphics/Color.h"
33 #include "platform/graphics/GraphicsContext.h" 33 #include "platform/graphics/GraphicsContext.h"
34 #include "platform/graphics/skia/SkiaUtils.h" 34 #include "platform/graphics/skia/SkiaUtils.h"
35 #include "third_party/skia/include/core/SkColorShader.h" 35 #include "third_party/skia/include/core/SkColorShader.h"
36 #include "third_party/skia/include/core/SkShader.h" 36 #include "third_party/skia/include/core/SkShader.h"
37 #include "third_party/skia/include/effects/SkGradientShader.h" 37 #include "third_party/skia/include/effects/SkGradientShader.h"
38 38
39 namespace WebCore { 39 namespace WebCore {
40 40
41 Gradient::Gradient(const FloatPoint& p0, const FloatPoint& p1) 41 Gradient::Gradient(const FloatPoint& p0, const FloatPoint& p1)
42 : m_radial(false) 42 : m_p0(p0)
43 , m_p0(p0)
44 , m_p1(p1) 43 , m_p1(p1)
45 , m_r0(0) 44 , m_r0(0)
46 , m_r1(0) 45 , m_r1(0)
47 , m_aspectRatio(1) 46 , m_aspectRatio(1)
47 , m_radial(false)
48 , m_stopsSorted(false) 48 , m_stopsSorted(false)
49 , m_shaderChanged(false)
49 , m_spreadMethod(SpreadMethodPad) 50 , m_spreadMethod(SpreadMethodPad)
50 , m_drawInPMColorSpace(false) 51 , m_drawInPMColorSpace(false)
51 { 52 {
52 } 53 }
53 54
54 Gradient::Gradient(const FloatPoint& p0, float r0, const FloatPoint& p1, float r 1, float aspectRatio) 55 Gradient::Gradient(const FloatPoint& p0, float r0, const FloatPoint& p1, float r 1, float aspectRatio)
55 : m_radial(true) 56 : m_p0(p0)
56 , m_p0(p0)
57 , m_p1(p1) 57 , m_p1(p1)
58 , m_r0(r0) 58 , m_r0(r0)
59 , m_r1(r1) 59 , m_r1(r1)
60 , m_aspectRatio(aspectRatio) 60 , m_aspectRatio(aspectRatio)
61 , m_radial(true)
61 , m_stopsSorted(false) 62 , m_stopsSorted(false)
63 , m_shaderChanged(false)
62 , m_spreadMethod(SpreadMethodPad) 64 , m_spreadMethod(SpreadMethodPad)
63 , m_drawInPMColorSpace(false) 65 , m_drawInPMColorSpace(false)
64 { 66 {
65 } 67 }
66 68
67 Gradient::~Gradient() 69 Gradient::~Gradient()
68 { 70 {
69 } 71 }
70 72
71 void Gradient::addColorStop(float value, const Color& color) 73 void Gradient::addColorStop(float value, const Color& color)
72 { 74 {
73 float r; 75 float r;
74 float g; 76 float g;
75 float b; 77 float b;
76 float a; 78 float a;
77 color.getRGBA(r, g, b, a); 79 color.getRGBA(r, g, b, a);
78 m_stops.append(ColorStop(value, r, g, b, a)); 80 m_stops.append(ColorStop(value, r, g, b, a));
79 81
80 m_stopsSorted = false; 82 m_stopsSorted = false;
83 m_shaderChanged = true;
81 m_gradient.clear(); 84 m_gradient.clear();
82 } 85 }
83 86
84 void Gradient::addColorStop(const Gradient::ColorStop& stop) 87 void Gradient::addColorStop(const Gradient::ColorStop& stop)
85 { 88 {
86 m_stops.append(stop); 89 m_stops.append(stop);
87 90
88 m_stopsSorted = false; 91 m_stopsSorted = false;
92 m_shaderChanged = true;
89 m_gradient.clear(); 93 m_gradient.clear();
90 } 94 }
91 95
92 static inline bool compareStops(const Gradient::ColorStop& a, const Gradient::Co lorStop& b) 96 static inline bool compareStops(const Gradient::ColorStop& a, const Gradient::Co lorStop& b)
93 { 97 {
94 return a.stop < b.stop; 98 return a.stop < b.stop;
95 } 99 }
96 100
97 void Gradient::sortStopsIfNecessary() 101 void Gradient::sortStopsIfNecessary()
98 { 102 {
(...skipping 28 matching lines...) Expand all
127 131
128 m_spreadMethod = spreadMethod; 132 m_spreadMethod = spreadMethod;
129 } 133 }
130 134
131 void Gradient::setDrawsInPMColorSpace(bool drawInPMColorSpace) 135 void Gradient::setDrawsInPMColorSpace(bool drawInPMColorSpace)
132 { 136 {
133 if (drawInPMColorSpace == m_drawInPMColorSpace) 137 if (drawInPMColorSpace == m_drawInPMColorSpace)
134 return; 138 return;
135 139
136 m_drawInPMColorSpace = drawInPMColorSpace; 140 m_drawInPMColorSpace = drawInPMColorSpace;
141 m_shaderChanged = true;
137 m_gradient.clear(); 142 m_gradient.clear();
138 } 143 }
139 144
140 void Gradient::setGradientSpaceTransform(const AffineTransform& gradientSpaceTra nsformation) 145 void Gradient::setGradientSpaceTransform(const AffineTransform& gradientSpaceTra nsformation)
141 { 146 {
142 if (m_gradientSpaceTransformation == gradientSpaceTransformation) 147 if (m_gradientSpaceTransformation == gradientSpaceTransformation)
143 return; 148 return;
144 149
145 m_gradientSpaceTransformation = gradientSpaceTransformation; 150 m_gradientSpaceTransformation = gradientSpaceTransformation;
146 if (m_gradient) 151 if (m_gradient)
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 SkPoint pts[2] = { m_p0, m_p1 }; 274 SkPoint pts[2] = { m_p0, m_p1 };
270 m_gradient = adoptRef(SkGradientShader::CreateLinear(pts, colors, pos, s tatic_cast<int>(countUsed), tile, 0, shouldDrawInPMColorSpace)); 275 m_gradient = adoptRef(SkGradientShader::CreateLinear(pts, colors, pos, s tatic_cast<int>(countUsed), tile, 0, shouldDrawInPMColorSpace));
271 } 276 }
272 277
273 if (!m_gradient) { 278 if (!m_gradient) {
274 // use last color, since our "geometry" was degenerate (e.g. radius==0) 279 // use last color, since our "geometry" was degenerate (e.g. radius==0)
275 m_gradient = adoptRef(new SkColorShader(colors[countUsed - 1])); 280 m_gradient = adoptRef(new SkColorShader(colors[countUsed - 1]));
276 } else { 281 } else {
277 m_gradient->setLocalMatrix(affineTransformToSkMatrix(m_gradientSpaceTran sformation)); 282 m_gradient->setLocalMatrix(affineTransformToSkMatrix(m_gradientSpaceTran sformation));
278 } 283 }
284 m_shaderChanged = true;
279 return m_gradient.get(); 285 return m_gradient.get();
280 } 286 }
281 287
282 } //namespace 288 } //namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698