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

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: Added missing virtual layout test to TestExpectations 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
« no previous file with comments | « Source/platform/graphics/GraphicsContext.h ('k') | Source/platform/graphics/GraphicsContextState.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/platform/graphics/GraphicsContext.cpp
diff --git a/Source/platform/graphics/GraphicsContext.cpp b/Source/platform/graphics/GraphicsContext.cpp
index 38d4105bd7b6f85283bc7d9e443f692781b8ef1a..cb3fb1b7c26cc44e63227e1650d438b52eb31521 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,18 @@ void GraphicsContext::setShadow(const FloatSize& offset, float blur, const Color
drawLooperBuilder->addUnmodifiedContent();
}
setDrawLooper(drawLooperBuilder.release());
+
+ if (shadowTransformMode == DrawLooperBuilder::ShadowIgnoresTransforms
Justin Novosad 2014/11/28 23:20:39 This is wrong by the way. SkDropShadowImageFilter
+ && shadowAlphaMode == DrawLooperBuilder::ShadowRespectsAlpha) {
+ // This image filter will be used in place of the drawLooper created above but only for drawing non-opaque bitmaps;
+ // see preparePaintForDrawRectToRect().
+ SkColor skColor = color.rgb();
+ // These constants are from RadiusToSigma() from DrawLooperBuilder.cpp.
+ const SkScalar sigma = 0.288675f * blur + 0.5f;
+ SkDropShadowImageFilter::ShadowMode dropShadowMode = shadowMode == DrawShadowAndForeground ? SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode : SkDropShadowImageFilter::kDrawShadowOnly_ShadowMode;
+ RefPtr<SkImageFilter> filter = adoptRef(SkDropShadowImageFilter::Create(offset.width(), offset.height(), sigma, sigma, skColor, dropShadowMode));
+ setDropShadowImageFilter(filter);
+ }
}
void GraphicsContext::setDrawLooper(PassOwnPtr<DrawLooperBuilder> drawLooperBuilder)
@@ -344,9 +357,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 +1996,18 @@ void GraphicsContext::preparePaintForDrawRectToRect(
const SkRect& destRect,
CompositeOperator compositeOp,
WebBlendMode blendMode,
+ bool isBitmapWithAlpha,
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() && isBitmapWithAlpha) {
+ paint->setImageFilter(this->dropShadowImageFilter());
+ } else {
+ paint->setLooper(this->drawLooper());
+ }
paint->setAntiAlias(shouldDrawAntiAliased(this, destRect));
InterpolationQuality resampling;
« no previous file with comments | « Source/platform/graphics/GraphicsContext.h ('k') | Source/platform/graphics/GraphicsContextState.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698