- GraphicsContext* c = drawingContext(); // Do not exit yet if !c because we may need to throw exceptions first
- CompositeOperator op = c ? c->compositeOperation() : CompositeSourceOver;
- blink::WebBlendMode blendMode = c ? c->blendModeOperation() : blink::WebBlendModeNormal;
- drawImageInternal(imageSource, sx, sy, sw, sh, dx, dy, dw, dh, exceptionState, op, blendMode, c);
+ drawImageInternal(imageSource, sx, sy, sw, sh, dx, dy, dw, dh, exceptionState);
+}
+
+static void drawVideo(GraphicsContext* c, CanvasImageSource* imageSource, FloatRect srcRect, FloatRect dstRect)
+{
+ HTMLVideoElement* video = static_cast<HTMLVideoElement*>(imageSource);
+ GraphicsContextStateSaver stateSaver(*c);
+ c->clip(dstRect);
+ c->translate(dstRect.x(), dstRect.y());
+ c->scale(dstRect.width() / srcRect.width(), dstRect.height() / srcRect.height());
+ c->translate(-srcRect.x(), -srcRect.y());
+ video->paintCurrentFrameInContext(c, IntRect(IntPoint(), IntSize(video->videoWidth(), video->videoHeight())));
+ stateSaver.restore();
+}
+
+static void drawImageOnContext(GraphicsContext* c, CanvasImageSource* imageSource, Image* image, const FloatRect& srcRect, const FloatRect& dstRect)
+{
+ if (!imageSource->isVideoElement()) {
+ c->drawImage(image, dstRect, srcRect, c->compositeOperation(), c->blendModeOperation());
+ } else {
+ drawVideo(c, static_cast<HTMLVideoElement*>(imageSource), srcRect, dstRect);
+ }