This source file includes following definitions.
- create
- detachDrawLooper
- addUnmodifiedContent
- addShadow
#include "config.h"
#include "platform/graphics/DrawLooperBuilder.h"
#include "platform/geometry/FloatSize.h"
#include "platform/graphics/Color.h"
#include "third_party/skia/include/core/SkColor.h"
#include "third_party/skia/include/core/SkColorFilter.h"
#include "third_party/skia/include/core/SkDrawLooper.h"
#include "third_party/skia/include/core/SkPaint.h"
#include "third_party/skia/include/core/SkXfermode.h"
#include "third_party/skia/include/effects/SkBlurMaskFilter.h"
#include "wtf/RefPtr.h"
namespace WebCore {
DrawLooperBuilder::DrawLooperBuilder() { }
DrawLooperBuilder::~DrawLooperBuilder() { }
PassOwnPtr<DrawLooperBuilder> DrawLooperBuilder::create()
{
return adoptPtr(new DrawLooperBuilder);
}
PassRefPtr<SkDrawLooper> DrawLooperBuilder::detachDrawLooper()
{
return adoptRef(m_skDrawLooperBuilder.detachLooper());
}
void DrawLooperBuilder::addUnmodifiedContent()
{
SkLayerDrawLooper::LayerInfo info;
m_skDrawLooperBuilder.addLayerOnTop(info);
}
void DrawLooperBuilder::addShadow(const FloatSize& offset, float blur, const Color& color,
ShadowTransformMode shadowTransformMode, ShadowAlphaMode shadowAlphaMode)
{
if (!color.alpha())
return;
SkColor skColor = color.rgb();
SkLayerDrawLooper::LayerInfo info;
switch (shadowAlphaMode) {
case ShadowRespectsAlpha:
info.fColorMode = SkXfermode::kDst_Mode;
break;
case ShadowIgnoresAlpha:
info.fColorMode = SkXfermode::kSrc_Mode;
break;
default:
ASSERT_NOT_REACHED();
}
if (blur)
info.fPaintBits |= SkLayerDrawLooper::kMaskFilter_Bit;
info.fPaintBits |= SkLayerDrawLooper::kColorFilter_Bit;
info.fOffset.set(offset.width(), offset.height());
info.fPostTranslate = (shadowTransformMode == ShadowIgnoresTransforms);
SkPaint* paint = m_skDrawLooperBuilder.addLayerOnTop(info);
if (blur) {
uint32_t mfFlags = SkBlurMaskFilter::kHighQuality_BlurFlag;
if (shadowTransformMode == ShadowIgnoresTransforms)
mfFlags |= SkBlurMaskFilter::kIgnoreTransform_BlurFlag;
RefPtr<SkMaskFilter> mf = adoptRef(SkBlurMaskFilter::Create(
(double)blur / 2.0, SkBlurMaskFilter::kNormal_BlurStyle, mfFlags));
paint->setMaskFilter(mf.get());
}
RefPtr<SkColorFilter> cf = adoptRef(SkColorFilter::CreateModeFilter(skColor, SkXfermode::kSrcIn_Mode));
paint->setColorFilter(cf.get());
}
}