Index: Source/platform/graphics/GraphicsContext.cpp |
diff --git a/Source/platform/graphics/GraphicsContext.cpp b/Source/platform/graphics/GraphicsContext.cpp |
index 927f44dcd19cacd9bfdc402a17104ee63c637592..8ec315286ba9781e0212b7efa82b432615ca44cc 100644 |
--- a/Source/platform/graphics/GraphicsContext.cpp |
+++ b/Source/platform/graphics/GraphicsContext.cpp |
@@ -42,7 +42,6 @@ |
#include "third_party/skia/include/core/SkRRect.h" |
#include "third_party/skia/include/core/SkRefCnt.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/SkPictureImageFilter.h" |
#include "third_party/skia/include/utils/SkNullCanvas.h" |
@@ -309,7 +308,7 @@ void GraphicsContext::setShadow(const FloatSize& offset, float blur, const Color |
setDrawLooper(drawLooperBuilder.release()); |
return; |
} |
- clearShadow(); |
+ clearDrawLooper(); |
return; |
} |
@@ -318,18 +317,6 @@ void GraphicsContext::setShadow(const FloatSize& offset, float blur, const Color |
drawLooperBuilder->addUnmodifiedContent(); |
} |
setDrawLooper(drawLooperBuilder.release()); |
- |
- if (shadowTransformMode == DrawLooperBuilder::ShadowIgnoresTransforms |
- && 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) |
@@ -348,22 +335,6 @@ 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(); |
-} |
- |
SkMatrix GraphicsContext::getTotalMatrix() const |
{ |
// FIXME: this is a hack to avoid changing all call sites of getTotalMatrix() to not use this method. |
@@ -450,7 +421,7 @@ void GraphicsContext::beginLayer(float opacity, SkXfermode::Mode xfermode, const |
SkRect skBounds = WebCoreFloatRectToSKRect(*bounds); |
saveLayer(&skBounds, &layerPaint); |
} else { |
- saveLayer(0, &layerPaint); |
+ saveLayer(nullptr, &layerPaint); |
} |
#if ENABLE(ASSERT) |
@@ -1032,7 +1003,41 @@ void GraphicsContext::drawImage(Image* image, const FloatRect& dest, const Float |
{ |
if (contextDisabled() || !image) |
return; |
- image->draw(this, dest, src, op, shouldRespectImageOrientation); |
+ |
+ SkPaint imagePaint = immutableState()->fillPaint(); |
+ imagePaint.setXfermodeMode(op); |
+ imagePaint.setFilterQuality(getFilterQuality(image, dest, src)); |
+ |
+ image->draw(m_canvas, imagePaint, dest, src, shouldRespectImageOrientation); |
+} |
+ |
+SkFilterQuality GraphicsContext::getFilterQuality(Image* image, const FloatRect& dest, const FloatRect& src) const |
+{ |
+ InterpolationQuality resampling; |
+ if (printing()) { |
+ resampling = InterpolationNone; |
+ } else if (image->isLazyDecodedBitmap()) { |
+ resampling = InterpolationHigh; |
+ } else { |
+ // Take into account scale applied to the canvas when computing sampling mode (e.g. CSS scale or page scale). |
f(malita)
2015/04/17 16:18:32
Not new to this CL, but let's add a comment here:
|
+ SkRect destRectTarget = dest; |
+ SkMatrix totalMatrix = getTotalMatrix(); |
+ if (!(totalMatrix.getType() & (SkMatrix::kAffine_Mask | SkMatrix::kPerspective_Mask))) |
+ totalMatrix.mapRect(&destRectTarget, dest); |
+ |
+ resampling = computeInterpolationQuality(totalMatrix, |
+ SkScalarToFloat(src.width()), SkScalarToFloat(src.height()), |
+ SkScalarToFloat(destRectTarget.width()), SkScalarToFloat(destRectTarget.height()), |
+ image->isImmutableBitmap()); |
+ } |
+ |
+ if (resampling == InterpolationNone) { |
+ // FIXME: This is to not break tests (it results in the filter bitmap flag |
+ // being set to true). We need to decide if we respect InterpolationNone |
+ // being returned from computeInterpolationQuality. |
+ resampling = InterpolationLow; |
+ } |
+ return static_cast<SkFilterQuality>(limitInterpolationQuality(this, resampling)); |
} |
void GraphicsContext::drawTiledImage(Image* image, const IntRect& destRect, const IntPoint& srcPoint, const IntSize& tileSize, SkXfermode::Mode op, const IntSize& repeatSpacing) |
@@ -1075,23 +1080,6 @@ void GraphicsContext::writePixels(const SkImageInfo& info, const void* pixels, s |
m_canvas->writePixels(info, pixels, rowBytes, x, y); |
} |
-void GraphicsContext::drawBitmapRect(const SkBitmap& bitmap, const SkRect* src, |
- const SkRect& dst, const SkPaint* paint) |
-{ |
- // Textures are bound to the blink main-thread GrContext, which can not be |
- // used on the compositor raster thread. |
- // FIXME: Mailbox support would make this possible in the GPU-raster case. |
- ASSERT(!isRecording() || !bitmap.getTexture()); |
- if (contextDisabled()) |
- return; |
- |
- SkCanvas::DrawBitmapRectFlags flags = |
- immutableState()->shouldClampToSourceRect() ? SkCanvas::kNone_DrawBitmapRectFlag : SkCanvas::kBleed_DrawBitmapRectFlag; |
- |
- ASSERT(m_canvas); |
- m_canvas->drawBitmapRectToRect(bitmap, src, dst, paint, flags); |
-} |
- |
void GraphicsContext::drawOval(const SkRect& oval, const SkPaint& paint) |
{ |
if (contextDisabled()) |
@@ -1630,81 +1618,4 @@ SkPMColor GraphicsContext::antiColors2(int index) |
} |
#endif |
-int GraphicsContext::preparePaintForDrawRectToRect( |
- SkPaint* paint, |
- const SkRect& srcRect, |
- const SkRect& destRect, |
- SkXfermode::Mode compositeOp, |
- bool isBitmapWithAlpha, |
- bool isLazyDecoded, |
- bool isDataComplete) const |
-{ |
- int initialSaveCount = m_canvas->getSaveCount(); |
- |
- paint->setColorFilter(this->colorFilter()); |
- paint->setAlpha(this->getNormalizedAlpha()); |
- bool usingImageFilter = false; |
- if (dropShadowImageFilter() && isBitmapWithAlpha) { |
- SkMatrix ctm = getTotalMatrix(); |
- SkMatrix invCtm; |
- if (ctm.invert(&invCtm)) { |
- usingImageFilter = true; |
- // The image filter is meant to ignore tranforms with respect to |
- // the shadow parameters. The matrix tweaks below ensures that the image |
- // filter is applied in post-transform space. We use concat() instead of |
- // setMatrix() in case this goes into a recording canvas which may need to |
- // respect a parent transform at playback time. |
- m_canvas->save(); |
- m_canvas->concat(invCtm); |
- SkRect bounds = destRect; |
- ctm.mapRect(&bounds); |
- SkRect filteredBounds; |
- dropShadowImageFilter()->computeFastBounds(bounds, &filteredBounds); |
- SkPaint layerPaint; |
- layerPaint.setXfermodeMode(compositeOp); |
- layerPaint.setImageFilter(dropShadowImageFilter()); |
- m_canvas->saveLayer(&filteredBounds, &layerPaint); |
- m_canvas->concat(ctm); |
- } |
- } |
- |
- if (!usingImageFilter) { |
- paint->setXfermodeMode(compositeOp); |
- paint->setLooper(this->drawLooper()); |
- } |
- |
- paint->setAntiAlias(shouldDrawAntiAliased(this, destRect)); |
- |
- InterpolationQuality resampling; |
- if (this->isAccelerated()) { |
- resampling = InterpolationLow; |
- } else if (this->printing()) { |
- resampling = InterpolationNone; |
- } else if (isLazyDecoded) { |
- resampling = InterpolationHigh; |
- } else { |
- // Take into account scale applied to the canvas when computing sampling mode (e.g. CSS scale or page scale). |
- SkRect destRectTarget = destRect; |
- SkMatrix totalMatrix = this->getTotalMatrix(); |
- if (!(totalMatrix.getType() & (SkMatrix::kAffine_Mask | SkMatrix::kPerspective_Mask))) |
- totalMatrix.mapRect(&destRectTarget, destRect); |
- |
- resampling = computeInterpolationQuality(totalMatrix, |
- SkScalarToFloat(srcRect.width()), SkScalarToFloat(srcRect.height()), |
- SkScalarToFloat(destRectTarget.width()), SkScalarToFloat(destRectTarget.height()), |
- isDataComplete); |
- } |
- |
- if (resampling == InterpolationNone) { |
- // FIXME: This is to not break tests (it results in the filter bitmap flag |
- // being set to true). We need to decide if we respect InterpolationNone |
- // being returned from computeInterpolationQuality. |
- resampling = InterpolationLow; |
- } |
- resampling = limitInterpolationQuality(this, resampling); |
- paint->setFilterQuality(static_cast<SkFilterQuality>(resampling)); |
- |
- return initialSaveCount; |
-} |
- |
} // namespace blink |