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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: Source/platform/graphics/GraphicsContext.cpp
diff --git a/Source/platform/graphics/GraphicsContext.cpp b/Source/platform/graphics/GraphicsContext.cpp
index 38d4105bd7b6f85283bc7d9e443f692781b8ef1a..cc3350a2215531796a67a14de8d8c4af33dedfdd 100644
--- a/Source/platform/graphics/GraphicsContext.cpp
+++ b/Source/platform/graphics/GraphicsContext.cpp
@@ -51,6 +51,7 @@
#include "third_party/skia/include/core/SkSurface.h"
#include "third_party/skia/include/effects/SkBlurMaskFilter.h"
#include "third_party/skia/include/effects/SkCornerPathEffect.h"
+#include "third_party/skia/include/effects/SkDropShadowImageFilter.h"
#include "third_party/skia/include/effects/SkLumaColorFilter.h"
#include "third_party/skia/include/effects/SkMatrixImageFilter.h"
#include "third_party/skia/include/effects/SkPictureImageFilter.h"
@@ -326,6 +327,16 @@ void GraphicsContext::setShadow(const FloatSize& offset, float blur, const Color
drawLooperBuilder->addUnmodifiedContent();
}
setDrawLooper(drawLooperBuilder.release());
+
+ if (shadowMode == DrawShadowAndForeground
+ && shadowTransformMode == DrawLooperBuilder::ShadowIgnoresTransforms
+ && shadowAlphaMode == DrawLooperBuilder::ShadowRespectsAlpha) {
+ // 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.
+ SkColor skColor = color.rgb();
+ 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.
+ RefPtr<SkImageFilter> filter = adoptRef(SkDropShadowImageFilter::Create(offset.width(), offset.height(), sigma, sigma, skColor));
+ setDropShadowImageFilter(filter);
+ }
}
void GraphicsContext::setDrawLooper(PassOwnPtr<DrawLooperBuilder> drawLooperBuilder)
@@ -344,9 +355,25 @@ void GraphicsContext::clearDrawLooper()
mutableState()->clearDrawLooper();
}
+void GraphicsContext::setDropShadowImageFilter(PassRefPtr<SkImageFilter> imageFilter)
+{
+ if (contextDisabled())
+ return;
+
+ mutableState()->setDropShadowImageFilter(imageFilter);
+}
+
+void GraphicsContext::clearDropShadowImageFilter()
+{
+ if (contextDisabled())
+ return;
+
+ mutableState()->clearDropShadowImageFilter();
+}
+
bool GraphicsContext::hasShadow() const
{
- return !!immutableState()->drawLooper();
+ return !!immutableState()->drawLooper() || !!immutableState()->dropShadowImageFilter();
}
bool GraphicsContext::getTransformedClipBounds(FloatRect* bounds) const
@@ -1967,13 +1994,18 @@ void GraphicsContext::preparePaintForDrawRectToRect(
const SkRect& destRect,
CompositeOperator compositeOp,
WebBlendMode blendMode,
+ 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.
bool isLazyDecoded,
bool isDataComplete) const
{
paint->setXfermodeMode(WebCoreCompositeToSkiaComposite(compositeOp, blendMode));
paint->setColorFilter(this->colorFilter());
paint->setAlpha(this->getNormalizedAlpha());
- paint->setLooper(this->drawLooper());
+ 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.
+ paint->setImageFilter(this->dropShadowImageFilter());
+ } else {
+ paint->setLooper(this->drawLooper());
+ }
paint->setAntiAlias(shouldDrawAntiAliased(this, destRect));
InterpolationQuality resampling;

Powered by Google App Engine
This is Rietveld 408576698