示例#1
0
void CrossfadeGeneratedImage::drawCrossfade(
    SkCanvas* canvas,
    const SkPaint& paint,
    ImageClampingMode clampMode,
    const ColorBehavior& colorBehavior) {
  FloatRect fromImageRect(FloatPoint(), FloatSize(m_fromImage->size()));
  FloatRect toImageRect(FloatPoint(), FloatSize(m_toImage->size()));
  FloatRect destRect((FloatPoint()), FloatSize(m_crossfadeSize));

  // TODO(junov): The various effects encoded into paint should probably be
  // applied here instead of inside the layer.  This probably faulty behavior
  // was maintained in order to preserve pre-existing behavior while refactoring
  // this code.  This should be investigated further. crbug.com/472634
  SkPaint layerPaint;
  layerPaint.setBlendMode(paint.getBlendMode());
  SkAutoCanvasRestore ar(canvas, false);
  canvas->saveLayer(nullptr, &layerPaint);

  SkPaint imagePaint(paint);
  imagePaint.setBlendMode(SkBlendMode::kSrcOver);
  int imageAlpha = clampedAlphaForBlending(1 - m_percentage);
  imagePaint.setAlpha(imageAlpha > 255 ? 255 : imageAlpha);
  imagePaint.setAntiAlias(paint.isAntiAlias());
  // TODO(junov): This code should probably be propagating the
  // RespectImageOrientationEnum from CrossfadeGeneratedImage::draw(). Code was
  // written this way during refactoring to avoid modifying existing behavior,
  // but this warrants further investigation. crbug.com/472634
  m_fromImage->draw(canvas, imagePaint, destRect, fromImageRect,
                    DoNotRespectImageOrientation, clampMode, colorBehavior);
  imagePaint.setBlendMode(SkBlendMode::kPlus);
  imageAlpha = clampedAlphaForBlending(m_percentage);
  imagePaint.setAlpha(imageAlpha > 255 ? 255 : imageAlpha);
  m_toImage->draw(canvas, imagePaint, destRect, toImageRect,
                  DoNotRespectImageOrientation, clampMode, colorBehavior);
}
void CanvasRenderingContext2DState::setGlobalAlpha(double alpha) {
    m_globalAlpha = alpha;
    m_strokeStyleDirty = true;
    m_fillStyleDirty = true;
    int imageAlpha = clampedAlphaForBlending(alpha);
    m_imagePaint.setAlpha(imageAlpha > 255 ? 255 : imageAlpha);
}
void CanvasRenderingContext2DState::updateFillStyle() const {
    if (!m_fillStyleDirty)
        return;

    int clampedAlpha = clampedAlphaForBlending(m_globalAlpha);
    ASSERT(m_fillStyle);
    m_fillStyle->applyToPaint(m_fillPaint);
    m_fillPaint.setColor(scaleAlpha(m_fillStyle->paintColor(), clampedAlpha));
    m_fillStyleDirty = false;
}
void CanvasRenderingContext2DState::updateStrokeStyle() const
{
    if (!m_strokeStyleDirty)
        return;

    int clampedAlpha = clampedAlphaForBlending(m_globalAlpha);
    ASSERT(m_strokeStyle);
    m_strokePaint.setShader(m_strokeStyle->shader());
    m_strokePaint.setColor(scaleAlpha(m_strokeStyle->paintColor(), clampedAlpha));
    m_strokeStyleDirty = false;
}
示例#5
0
SkColor scaleAlpha(SkColor color, float alpha)
{
    return scaleAlpha(color, clampedAlphaForBlending(alpha));
}