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

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

Issue 669123002: Fixed Shadow blur for transparent objects (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fixed some comments Created 6 years, 2 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) 2003, 2004, 2005, 2006, 2009 Apple Inc. All rights reserved. 2 * Copyright (C) 2003, 2004, 2005, 2006, 2009 Apple Inc. All rights reserved.
3 * Copyright (C) 2013 Google Inc. All rights reserved. 3 * Copyright (C) 2013 Google Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 #include "third_party/skia/include/core/SkColorFilter.h" 44 #include "third_party/skia/include/core/SkColorFilter.h"
45 #include "third_party/skia/include/core/SkData.h" 45 #include "third_party/skia/include/core/SkData.h"
46 #include "third_party/skia/include/core/SkDevice.h" 46 #include "third_party/skia/include/core/SkDevice.h"
47 #include "third_party/skia/include/core/SkPicture.h" 47 #include "third_party/skia/include/core/SkPicture.h"
48 #include "third_party/skia/include/core/SkPictureRecorder.h" 48 #include "third_party/skia/include/core/SkPictureRecorder.h"
49 #include "third_party/skia/include/core/SkRRect.h" 49 #include "third_party/skia/include/core/SkRRect.h"
50 #include "third_party/skia/include/core/SkRefCnt.h" 50 #include "third_party/skia/include/core/SkRefCnt.h"
51 #include "third_party/skia/include/core/SkSurface.h" 51 #include "third_party/skia/include/core/SkSurface.h"
52 #include "third_party/skia/include/effects/SkBlurMaskFilter.h" 52 #include "third_party/skia/include/effects/SkBlurMaskFilter.h"
53 #include "third_party/skia/include/effects/SkCornerPathEffect.h" 53 #include "third_party/skia/include/effects/SkCornerPathEffect.h"
54 #include "third_party/skia/include/effects/SkDropShadowImageFilter.h"
54 #include "third_party/skia/include/effects/SkLumaColorFilter.h" 55 #include "third_party/skia/include/effects/SkLumaColorFilter.h"
55 #include "third_party/skia/include/effects/SkMatrixImageFilter.h" 56 #include "third_party/skia/include/effects/SkMatrixImageFilter.h"
56 #include "third_party/skia/include/effects/SkPictureImageFilter.h" 57 #include "third_party/skia/include/effects/SkPictureImageFilter.h"
57 #include "third_party/skia/include/gpu/GrRenderTarget.h" 58 #include "third_party/skia/include/gpu/GrRenderTarget.h"
58 #include "third_party/skia/include/gpu/GrTexture.h" 59 #include "third_party/skia/include/gpu/GrTexture.h"
59 #include "wtf/Assertions.h" 60 #include "wtf/Assertions.h"
60 #include "wtf/MathExtras.h" 61 #include "wtf/MathExtras.h"
61 62
62 namespace { 63 namespace {
63 64
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 } 320 }
320 clearShadow(); 321 clearShadow();
321 return; 322 return;
322 } 323 }
323 324
324 drawLooperBuilder->addShadow(offset, blur, color, shadowTransformMode, shado wAlphaMode); 325 drawLooperBuilder->addShadow(offset, blur, color, shadowTransformMode, shado wAlphaMode);
325 if (shadowMode == DrawShadowAndForeground) { 326 if (shadowMode == DrawShadowAndForeground) {
326 drawLooperBuilder->addUnmodifiedContent(); 327 drawLooperBuilder->addUnmodifiedContent();
327 } 328 }
328 setDrawLooper(drawLooperBuilder.release()); 329 setDrawLooper(drawLooperBuilder.release());
330
331 if (shadowMode == DrawShadowAndForeground
332 && shadowTransformMode == DrawLooperBuilder::ShadowIgnoresTransforms
333 && shadowAlphaMode == DrawLooperBuilder::ShadowRespectsAlpha) {
334 // This image filter will only be used to replace the drawLooper created above if the image is not opaque
Stephen White 2014/10/23 19:08:49 Nit: "the image" here suggests we're always drawin
sugoi1 2014/10/23 20:25:14 Done.
335 SkColor skColor = color.rgb();
336 const SkScalar sigma = 0.288675f * blur + 0.5f;
Stephen White 2014/10/23 19:08:49 Nit: add a comment describing the origin of this c
sugoi1 2014/10/23 20:25:14 Done.
337 RefPtr<SkImageFilter> filter = adoptRef(SkDropShadowImageFilter::Create( offset.width(), offset.height(), sigma, sigma, skColor));
338 setDropShadowImageFilter(filter);
339 }
329 } 340 }
330 341
331 void GraphicsContext::setDrawLooper(PassOwnPtr<DrawLooperBuilder> drawLooperBuil der) 342 void GraphicsContext::setDrawLooper(PassOwnPtr<DrawLooperBuilder> drawLooperBuil der)
332 { 343 {
333 if (contextDisabled()) 344 if (contextDisabled())
334 return; 345 return;
335 346
336 mutableState()->setDrawLooper(drawLooperBuilder->detachDrawLooper()); 347 mutableState()->setDrawLooper(drawLooperBuilder->detachDrawLooper());
337 } 348 }
338 349
339 void GraphicsContext::clearDrawLooper() 350 void GraphicsContext::clearDrawLooper()
340 { 351 {
341 if (contextDisabled()) 352 if (contextDisabled())
342 return; 353 return;
343 354
344 mutableState()->clearDrawLooper(); 355 mutableState()->clearDrawLooper();
345 } 356 }
346 357
358 void GraphicsContext::setDropShadowImageFilter(PassRefPtr<SkImageFilter> imageFi lter)
359 {
360 if (contextDisabled())
361 return;
362
363 mutableState()->setDropShadowImageFilter(imageFilter);
364 }
365
366 void GraphicsContext::clearDropShadowImageFilter()
367 {
368 if (contextDisabled())
369 return;
370
371 mutableState()->clearDropShadowImageFilter();
372 }
373
347 bool GraphicsContext::hasShadow() const 374 bool GraphicsContext::hasShadow() const
348 { 375 {
349 return !!immutableState()->drawLooper(); 376 return !!immutableState()->drawLooper() || !!immutableState()->dropShadowIma geFilter();
350 } 377 }
351 378
352 bool GraphicsContext::getTransformedClipBounds(FloatRect* bounds) const 379 bool GraphicsContext::getTransformedClipBounds(FloatRect* bounds) const
353 { 380 {
354 if (contextDisabled()) 381 if (contextDisabled())
355 return false; 382 return false;
356 ASSERT(m_canvas); 383 ASSERT(m_canvas);
357 SkIRect skIBounds; 384 SkIRect skIBounds;
358 if (!m_canvas->getClipDeviceBounds(&skIBounds)) 385 if (!m_canvas->getClipDeviceBounds(&skIBounds))
359 return false; 386 return false;
(...skipping 1600 matching lines...) Expand 10 before | Expand all | Expand 10 after
1960 m_textRegion.join(textRect); 1987 m_textRegion.join(textRect);
1961 } 1988 }
1962 } 1989 }
1963 1990
1964 void GraphicsContext::preparePaintForDrawRectToRect( 1991 void GraphicsContext::preparePaintForDrawRectToRect(
1965 SkPaint* paint, 1992 SkPaint* paint,
1966 const SkRect& srcRect, 1993 const SkRect& srcRect,
1967 const SkRect& destRect, 1994 const SkRect& destRect,
1968 CompositeOperator compositeOp, 1995 CompositeOperator compositeOp,
1969 WebBlendMode blendMode, 1996 WebBlendMode blendMode,
1997 bool isOpaque,
Justin Novosad 2014/10/23 17:59:22 bikeshed: For readability it should be clear that
sugoi1 2014/10/23 20:25:14 Done.
1970 bool isLazyDecoded, 1998 bool isLazyDecoded,
1971 bool isDataComplete) const 1999 bool isDataComplete) const
1972 { 2000 {
1973 paint->setXfermodeMode(WebCoreCompositeToSkiaComposite(compositeOp, blendMod e)); 2001 paint->setXfermodeMode(WebCoreCompositeToSkiaComposite(compositeOp, blendMod e));
1974 paint->setColorFilter(this->colorFilter()); 2002 paint->setColorFilter(this->colorFilter());
1975 paint->setAlpha(this->getNormalizedAlpha()); 2003 paint->setAlpha(this->getNormalizedAlpha());
1976 paint->setLooper(this->drawLooper()); 2004 if (this->dropShadowImageFilter() && !isOpaque) {
Stephen White 2014/10/23 19:08:49 I was about to say we don't use "this->" in Blink
sugoi1 2014/10/23 20:25:14 Acknowledged.
2005 paint->setImageFilter(this->dropShadowImageFilter());
2006 } else {
2007 paint->setLooper(this->drawLooper());
2008 }
1977 paint->setAntiAlias(shouldDrawAntiAliased(this, destRect)); 2009 paint->setAntiAlias(shouldDrawAntiAliased(this, destRect));
1978 2010
1979 InterpolationQuality resampling; 2011 InterpolationQuality resampling;
1980 if (this->isAccelerated()) { 2012 if (this->isAccelerated()) {
1981 resampling = InterpolationLow; 2013 resampling = InterpolationLow;
1982 } else if (this->printing()) { 2014 } else if (this->printing()) {
1983 resampling = InterpolationNone; 2015 resampling = InterpolationNone;
1984 } else if (isLazyDecoded) { 2016 } else if (isLazyDecoded) {
1985 resampling = InterpolationHigh; 2017 resampling = InterpolationHigh;
1986 } else { 2018 } else {
(...skipping 13 matching lines...) Expand all
2000 // FIXME: This is to not break tests (it results in the filter bitmap fl ag 2032 // FIXME: This is to not break tests (it results in the filter bitmap fl ag
2001 // being set to true). We need to decide if we respect InterpolationNone 2033 // being set to true). We need to decide if we respect InterpolationNone
2002 // being returned from computeInterpolationQuality. 2034 // being returned from computeInterpolationQuality.
2003 resampling = InterpolationLow; 2035 resampling = InterpolationLow;
2004 } 2036 }
2005 resampling = limitInterpolationQuality(this, resampling); 2037 resampling = limitInterpolationQuality(this, resampling);
2006 paint->setFilterLevel(static_cast<SkPaint::FilterLevel>(resampling)); 2038 paint->setFilterLevel(static_cast<SkPaint::FilterLevel>(resampling));
2007 } 2039 }
2008 2040
2009 } // namespace blink 2041 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698