Пример #1
0
void Image::drawPattern(GraphicsContext& context,
                        const FloatRect& floatSrcRect,
                        const FloatSize& scale,
                        const FloatPoint& phase,
                        SkBlendMode compositeOp,
                        const FloatRect& destRect,
                        const FloatSize& repeatSpacing) {
  TRACE_EVENT0("skia", "Image::drawPattern");

  sk_sp<SkImage> image = imageForCurrentFrame();
  if (!image)
    return;

  FloatRect normSrcRect = floatSrcRect;

  normSrcRect.intersect(FloatRect(0, 0, image->width(), image->height()));
  if (destRect.isEmpty() || normSrcRect.isEmpty())
    return;  // nothing to draw

  SkMatrix localMatrix;
  // We also need to translate it such that the origin of the pattern is the
  // origin of the destination rect, which is what WebKit expects. Skia uses
  // the coordinate system origin as the base for the pattern. If WebKit wants
  // a shifted image, it will shift it from there using the localMatrix.
  const float adjustedX = phase.x() + normSrcRect.x() * scale.width();
  const float adjustedY = phase.y() + normSrcRect.y() * scale.height();
  localMatrix.setTranslate(SkFloatToScalar(adjustedX),
                           SkFloatToScalar(adjustedY));

  // Because no resizing occurred, the shader transform should be
  // set to the pattern's transform, which just includes scale.
  localMatrix.preScale(scale.width(), scale.height());

  // Fetch this now as subsetting may swap the image.
  auto imageID = image->uniqueID();

  image = image->makeSubset(enclosingIntRect(normSrcRect));
  if (!image)
    return;

  {
    SkPaint paint = context.fillPaint();
    paint.setColor(SK_ColorBLACK);
    paint.setBlendMode(static_cast<SkBlendMode>(compositeOp));
    paint.setFilterQuality(
        context.computeFilterQuality(this, destRect, normSrcRect));
    paint.setAntiAlias(context.shouldAntialias());
    paint.setShader(createPatternShader(
        image.get(), localMatrix, paint,
        FloatSize(repeatSpacing.width() / scale.width(),
                  repeatSpacing.height() / scale.height())));
    context.drawRect(destRect, paint);
  }

  if (currentFrameIsLazyDecoded())
    PlatformInstrumentation::didDrawLazyPixelRef(imageID);
}
Пример #2
0
void CrossfadeGeneratedImage::drawTile(GraphicsContext& context,
                                       const FloatRect& srcRect) {
  // Draw nothing if either of the images hasn't loaded yet.
  if (m_fromImage == Image::nullImage() || m_toImage == Image::nullImage())
    return;

  SkPaint paint = context.fillPaint();
  paint.setBlendMode(SkBlendMode::kSrcOver);
  paint.setAntiAlias(context.shouldAntialias());
  FloatRect destRect((FloatPoint()), FloatSize(m_crossfadeSize));
  paint.setFilterQuality(context.computeFilterQuality(this, destRect, srcRect));
  drawCrossfade(context.canvas(), paint, ClampImageToSourceRect);
}