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

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

Issue 1331533002: [poc] curve-filter Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fix CanvasRenderingContext2D::createPattern crash for #40 Created 4 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 10 matching lines...) Expand all
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
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/ColorSpaceFilter.h"
32 #include "platform/graphics/ColorSpaceProfile.h"
31 #include "platform/graphics/GraphicsContext.h" 33 #include "platform/graphics/GraphicsContext.h"
34 #include "platform/graphics/GraphicsScreen.h"
32 #include "platform/graphics/skia/SkiaUtils.h" 35 #include "platform/graphics/skia/SkiaUtils.h"
33 #include "third_party/skia/include/core/SkColor.h" 36 #include "third_party/skia/include/core/SkColor.h"
37 #include "third_party/skia/include/core/SkColorFilter.h"
34 #include "third_party/skia/include/core/SkShader.h" 38 #include "third_party/skia/include/core/SkShader.h"
35 #include "third_party/skia/include/effects/SkGradientShader.h" 39 #include "third_party/skia/include/effects/SkGradientShader.h"
36 #include <algorithm> 40 #include <algorithm>
37 41
38 typedef Vector<SkScalar, 8> ColorStopOffsetVector; 42 typedef Vector<SkScalar, 8> ColorStopOffsetVector;
39 typedef Vector<SkColor, 8> ColorStopColorVector; 43 typedef Vector<SkColor, 8> ColorStopColorVector;
40 44
41 namespace blink { 45 namespace blink {
42 46
43 Gradient::Gradient(const FloatPoint& p0, const FloatPoint& p1) 47 Gradient::Gradient(const FloatPoint& p0, const FloatPoint& p1)
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 } else { 248 } else {
245 SkPoint pts[2] = { m_p0.data(), m_p1.data() }; 249 SkPoint pts[2] = { m_p0.data(), m_p1.data() };
246 SkMatrix localMatrix = affineTransformToSkMatrix(m_gradientSpaceTransfor mation); 250 SkMatrix localMatrix = affineTransformToSkMatrix(m_gradientSpaceTransfor mation);
247 m_gradient = adoptRef(SkGradientShader::CreateLinear(pts, colors.data(), pos.data(), static_cast<int>(countUsed), tile, shouldDrawInPMColorSpace, &local Matrix)); 251 m_gradient = adoptRef(SkGradientShader::CreateLinear(pts, colors.data(), pos.data(), static_cast<int>(countUsed), tile, shouldDrawInPMColorSpace, &local Matrix));
248 } 252 }
249 253
250 if (!m_gradient) { 254 if (!m_gradient) {
251 // use last color, since our "geometry" was degenerate (e.g. radius==0) 255 // use last color, since our "geometry" was degenerate (e.g. radius==0)
252 m_gradient = adoptRef(SkShader::CreateColorShader(colors[countUsed - 1]) ); 256 m_gradient = adoptRef(SkShader::CreateColorShader(colors[countUsed - 1]) );
253 } 257 }
258
254 return m_gradient.get(); 259 return m_gradient.get();
255 } 260 }
256 261
257 void Gradient::applyToPaint(SkPaint& paint) 262 void Gradient::applyToPaint(SkPaint& paint)
258 { 263 {
259 paint.setShader(shader()); 264 if (!imageColorProfilesEnabled()) {
265 applyShaderToPaintInternal(shader(), paint);
266 return;
267 }
260 268
261 // Legacy behavior: gradients are always dithered. 269 RELEASE_ASSERT(currentScreenId());
262 paint.setDither(true); 270
271 // FIXME: the default color transform sRGB->screen is hot: Find a way to cac he it. Add API to retrieve it.
272
273 RefPtr<SkColorFilter> colorTransform = createColorSpaceFilter(screenColorPro file(ScreenDevice::sRGB).get(), screenColorProfile(currentScreenId()).get());
274 if (!colorTransform) {
275 applyShaderToPaintInternal(shader(), paint);
276 return;
277 }
278
279 RefPtr<SkShader> transformShader = adoptRef(shader()->newWithColorFilter(col orTransform.get()));
280 if (!transformShader) {
281 applyShaderToPaintInternal(shader(), paint);
282 return;
283 }
284
285 // Optionally, find a way to cache the color transformed paint shader too.
286 applyShaderToPaintInternal(transformShader.get(), paint);
263 } 287 }
288
264 } // namespace blink 289 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698