Changeset 45060 in webkit
- Timestamp:
- Jun 23, 2009 11:19:31 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r45039 r45060 1 2009-06-23 Oliver Hunt <oliver@apple.com> and Eric Carlson <eric.carlson@apple.com> 2 3 Reviewed by Sam Weinig and Dave Hyatt. 4 5 <rdar://problem/6164797> Add Canvas API to allow drawing of <video> frames 6 <https://bugs.webkit.org/show_bug.cgi?id=25920> 7 8 Add tests for drawing a video to the canvas element. 9 10 * media/video-canvas-expected.txt: Added. 11 * media/video-canvas.html: Added. 12 1 13 2009-06-23 Oliver Hunt <oliver@apple.com> 2 14 -
trunk/WebCore/ChangeLog
r45038 r45060 1 2009-06-23 Oliver Hunt <oliver@apple.com> and Eric Carlson <eric.carlson@apple.com> 2 3 Reviewed by Sam Weinig and Dave Hyatt. 4 5 <rdar://problem/6164797> Add Canvas API to allow drawing of <video> frames 6 <https://bugs.webkit.org/show_bug.cgi?id=25920> 7 8 Add support for drawing the contents of the video element to the canvas 9 in accordance with the current HTML5 draft. 10 11 Test: media/video-canvas.html 12 13 * bindings/js/JSCanvasRenderingContext2DCustom.cpp: 14 (WebCore::JSCanvasRenderingContext2D::drawImage): 15 Standard custom bindings stuff we need to do for all canvas methods. 16 * html/CanvasRenderingContext2D.cpp: 17 (WebCore::size): Helper function for finding the size of a video element 18 (WebCore::CanvasRenderingContext2D::checkOrigin): moved up in the file. 19 (WebCore::CanvasRenderingContext2D::drawImage): The various overloads of HTML5's drawImage(<video>) 20 * html/CanvasRenderingContext2D.h: 21 * html/HTMLMediaElement.h: 22 (WebCore::HTMLMediaElement::hasSingleSecurityOrigin): 23 hasSingleSecurityOrigin is needed for security, currently all implementations are trivial 24 as we force QT to maintain a single origin. 25 * html/HTMLVideoElement.cpp: 26 (WebCore::HTMLVideoElement::paint): 27 Paint routine on video so we don't have to look at MediaPlayer directly 28 * html/HTMLVideoElement.h: 29 * platform/graphics/MediaPlayer.cpp: 30 (WebCore::NullMediaPlayerPrivate::hasSingleSecurityOrigin): 31 (WebCore::MediaPlayer::hasSingleSecurityOrigin): 32 Default implementations of hasSingleSecurityOrigin 33 * platform/graphics/MediaPlayer.h: 34 * platform/graphics/MediaPlayerPrivate.h: 35 * platform/graphics/mac/MediaPlayerPrivateQTKit.h: 36 * platform/graphics/mac/MediaPlayerPrivateQTKit.mm: 37 (WebCore::MediaPlayerPrivate::setUpVideoRendering): 38 A video may need a player now even if it is not visible. 39 (WebCore::MediaPlayerPrivate::hasSingleSecurityOrigin): 40 Always return true due to restrictions we've placed on QT. 41 * platform/graphics/win/MediaPlayerPrivateQuickTimeWin.cpp: 42 (WebCore::MediaPlayerPrivate::paint): 43 Jump through some hoops to allow windows QT to draw to an intermediate buffer. 44 In the long term we'd like to cache the HDC, but this will do for now. 45 (WebCore::MediaPlayerPrivate::hasSingleSecurityOrigin): 46 * platform/graphics/win/MediaPlayerPrivateQuickTimeWin.h: 47 As for Mac we force QT to only allow same origin loads. 48 1 49 2009-06-23 Adam Langley <agl@google.com> 2 50 -
trunk/WebCore/bindings/js/JSCanvasRenderingContext2DCustom.cpp
r43122 r45060 1 1 /* 2 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.2 * Copyright (C) 2006, 2007, 2009 Apple Inc. All rights reserved. 3 3 * 4 4 * This library is free software; you can redistribute it and/or … … 29 29 #include "HTMLCanvasElement.h" 30 30 #include "HTMLImageElement.h" 31 #include "HTMLVideoElement.h" 31 32 #include "ImageData.h" 32 33 #include "JSCanvasGradient.h" … … 34 35 #include "JSHTMLCanvasElement.h" 35 36 #include "JSHTMLImageElement.h" 37 #include "JSHTMLVideoElement.h" 36 38 #include "JSImageData.h" 37 39 #include <runtime/Error.h> … … 231 233 return throwError(exec, SyntaxError); 232 234 } 235 #if ENABLE(VIDEO) 236 } else if (o->inherits(&JSHTMLVideoElement::s_info)) { 237 HTMLVideoElement* video = static_cast<HTMLVideoElement*>(static_cast<JSHTMLElement*>(o)->impl()); 238 switch (args.size()) { 239 case 3: 240 context->drawImage(video, args.at(1).toFloat(exec), args.at(2).toFloat(exec)); 241 break; 242 case 5: 243 context->drawImage(video, args.at(1).toFloat(exec), args.at(2).toFloat(exec), 244 args.at(3).toFloat(exec), args.at(4).toFloat(exec), ec); 245 setDOMException(exec, ec); 246 break; 247 case 9: 248 context->drawImage(video, FloatRect(args.at(1).toFloat(exec), args.at(2).toFloat(exec), 249 args.at(3).toFloat(exec), args.at(4).toFloat(exec)), 250 FloatRect(args.at(5).toFloat(exec), args.at(6).toFloat(exec), 251 args.at(7).toFloat(exec), args.at(8).toFloat(exec)), ec); 252 setDOMException(exec, ec); 253 break; 254 default: 255 return throwError(exec, SyntaxError); 256 } 257 #endif 233 258 } else { 234 259 setDOMException(exec, TYPE_MISMATCH_ERR); -
trunk/WebCore/html/CanvasRenderingContext2D.cpp
r44542 r45060 1 1 /* 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. 3 3 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) 4 4 * Copyright (C) 2007 Alp Toker <alp@atoker.com> … … 57 57 #include "StrokeStyleApplier.h" 58 58 #include "TextMetrics.h" 59 #include "HTMLVideoElement.h" 59 60 #include <stdio.h> 60 61 … … 912 913 return IntSize(); 913 914 } 915 916 static IntSize size(HTMLVideoElement* video) 917 { 918 if (MediaPlayer* player = video->player()) 919 return player->naturalSize(); 920 return IntSize(); 921 } 914 922 915 923 static inline FloatRect normalizeRect(const FloatRect& rect) … … 921 929 } 922 930 931 void CanvasRenderingContext2D::checkOrigin(const KURL& url) 932 { 933 RefPtr<SecurityOrigin> origin = SecurityOrigin::create(url); 934 if (!m_canvas->document()->securityOrigin()->canAccess(origin.get())) 935 m_canvas->setOriginTainted(); 936 } 937 923 938 void CanvasRenderingContext2D::drawImage(HTMLImageElement* image, float x, float y) 924 939 { … … 935 950 IntSize s = size(image); 936 951 drawImage(image, FloatRect(0, 0, s.width(), s.height()), FloatRect(x, y, width, height), ec); 937 }938 939 void CanvasRenderingContext2D::checkOrigin(const KURL& url)940 {941 RefPtr<SecurityOrigin> origin = SecurityOrigin::create(url);942 if (!m_canvas->document()->securityOrigin()->canAccess(origin.get()))943 m_canvas->setOriginTainted();944 952 } 945 953 … … 1032 1040 willDraw(destRect); // This call comes after drawImage, since the buffer we draw into may be our own, and we need to make sure it is dirty. 1033 1041 // FIXME: Arguably willDraw should become didDraw and occur after drawing calls and not before them to avoid problems like this. 1042 } 1043 1044 void CanvasRenderingContext2D::drawImage(HTMLVideoElement* video, float x, float y) 1045 { 1046 ASSERT(video); 1047 IntSize s = size(video); 1048 ExceptionCode ec; 1049 drawImage(video, x, y, s.width(), s.height(), ec); 1050 } 1051 1052 void CanvasRenderingContext2D::drawImage(HTMLVideoElement* video, 1053 float x, float y, float width, float height, ExceptionCode& ec) 1054 { 1055 ASSERT(video); 1056 IntSize s = size(video); 1057 drawImage(video, FloatRect(0, 0, s.width(), s.height()), FloatRect(x, y, width, height), ec); 1058 } 1059 1060 void CanvasRenderingContext2D::drawImage(HTMLVideoElement* video, const FloatRect& srcRect, const FloatRect& dstRect, 1061 ExceptionCode& ec) 1062 { 1063 ASSERT(video); 1064 1065 ec = 0; 1066 FloatRect videoRect = FloatRect(FloatPoint(), size(video)); 1067 if (!videoRect.contains(normalizeRect(srcRect)) || srcRect.width() == 0 || srcRect.height() == 0) { 1068 ec = INDEX_SIZE_ERR; 1069 return; 1070 } 1071 1072 if (!dstRect.width() || !dstRect.height()) 1073 return; 1074 1075 GraphicsContext* c = drawingContext(); 1076 if (!c) 1077 return; 1078 if (!state().m_invertibleCTM) 1079 return; 1080 1081 if (m_canvas->originClean()) 1082 checkOrigin(video->src()); 1083 1084 if (m_canvas->originClean() && !video->hasSingleSecurityOrigin()) 1085 m_canvas->setOriginTainted(); 1086 1087 FloatRect sourceRect = c->roundToDevicePixels(srcRect); 1088 FloatRect destRect = c->roundToDevicePixels(dstRect); 1089 willDraw(destRect); 1090 1091 c->save(); 1092 c->clip(destRect); 1093 c->translate(destRect.x(), destRect.y()); 1094 c->scale(FloatSize(destRect.width()/sourceRect.width(), destRect.height()/sourceRect.height())); 1095 c->translate(-sourceRect.x(), -sourceRect.y()); 1096 video->paint(c, IntRect(IntPoint(), size(video))); 1097 c->restore(); 1034 1098 } 1035 1099 -
trunk/WebCore/html/CanvasRenderingContext2D.h
r41616 r45060 1 1 /* 2 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.2 * Copyright (C) 2006, 2007, 2009 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 48 48 class HTMLCanvasElement; 49 49 class HTMLImageElement; 50 class HTMLVideoElement; 50 51 class ImageData; 51 52 class KURL; … … 160 161 void drawImage(HTMLCanvasElement*, float x, float y, float width, float height, ExceptionCode&); 161 162 void drawImage(HTMLCanvasElement*, const FloatRect& srcRect, const FloatRect& dstRect, ExceptionCode&); 163 void drawImage(HTMLVideoElement*, float x, float y); 164 void drawImage(HTMLVideoElement*, float x, float y, float width, float height, ExceptionCode&); 165 void drawImage(HTMLVideoElement*, const FloatRect& srcRect, const FloatRect& dstRect, ExceptionCode&); 162 166 163 167 void drawImageFromRect(HTMLImageElement*, float sx, float sy, float sw, float sh, -
trunk/WebCore/html/HTMLMediaElement.h
r44999 r45060 144 144 #endif 145 145 146 bool hasSingleSecurityOrigin() const { return !m_player || m_player->hasSingleSecurityOrigin(); } 147 146 148 protected: 147 149 float getTimeOffsetAttribute(const QualifiedName&, float valueOnError) const; -
trunk/WebCore/html/HTMLVideoElement.cpp
r43187 r45060 1 1 /* 2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.2 * Copyright (C) 2007, 2008, 2009 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 187 187 } 188 188 189 } 190 #endif 189 void HTMLVideoElement::paint(GraphicsContext* context, const IntRect& r) 190 { 191 // FIXME: We should also be able to paint the poster image. 192 193 MediaPlayer* player = HTMLMediaElement::player(); 194 if (!player) 195 return; 196 197 player->setVisible(true); // Make player visible or it won't draw. 198 player->paint(context, r); 199 } 200 201 } 202 #endif -
trunk/WebCore/html/HTMLVideoElement.h
r41042 r45060 1 1 /* 2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.2 * Copyright (C) 2007, 2008, 2009 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 67 67 void updatePosterImage(); 68 68 69 // Used by canvas to gain raw pixel access 70 void paint(GraphicsContext*, const IntRect&); 71 69 72 private: 70 73 OwnPtr<HTMLImageLoader> m_imageLoader; -
trunk/WebCore/platform/graphics/MediaPlayer.cpp
r44999 r45060 104 104 virtual void setMediaPlayerProxy(WebMediaPlayerProxy*) { } 105 105 #endif 106 107 virtual bool hasSingleSecurityOrigin() const { return true; } 106 108 }; 107 109 … … 530 532 } 531 533 532 } 533 #endif 534 bool MediaPlayer::hasSingleSecurityOrigin() const 535 { 536 return m_private->hasSingleSecurityOrigin(); 537 } 538 539 } 540 #endif -
trunk/WebCore/platform/graphics/MediaPlayer.h
r44999 r45060 192 192 #endif 193 193 194 bool hasSingleSecurityOrigin() const; 195 194 196 private: 195 197 static void initializeMediaEngines(); -
trunk/WebCore/platform/graphics/MediaPlayerPrivate.h
r44999 r45060 100 100 virtual void acceleratedRenderingStateChanged() { } 101 101 #endif 102 103 virtual bool hasSingleSecurityOrigin() const { return false; } 102 104 }; 103 105 -
trunk/WebCore/platform/graphics/mac/MediaPlayerPrivateQTKit.h
r44999 r45060 69 69 void didEnd(); 70 70 71 bool hasSingleSecurityOrigin() const; 71 72 private: 72 73 MediaPlayerPrivate(MediaPlayer*); -
trunk/WebCore/platform/graphics/mac/MediaPlayerPrivateQTKit.mm
r44999 r45060 498 498 MediaRenderingMode currentMode = currentRenderingMode(); 499 499 MediaRenderingMode preferredMode = preferredRenderingMode(); 500 if (currentMode == preferredMode )500 if (currentMode == preferredMode && currentMode != MediaRenderingNone) 501 501 return; 502 502 … … 505 505 506 506 switch (preferredMode) { 507 case MediaRenderingNone:508 break;509 507 case MediaRenderingMovieView: 510 508 createQTMovieView(); 511 509 break; 510 case MediaRenderingNone: 512 511 case MediaRenderingSoftwareRenderer: 513 512 createQTVideoRenderer(); … … 1310 1309 #endif 1311 1310 1311 bool MediaPlayerPrivate::hasSingleSecurityOrigin() const 1312 { 1313 // We tell quicktime to disallow resources that come from different origins 1314 // so we know all media is single origin. 1315 return true; 1316 } 1317 1312 1318 } // namespace WebCore 1313 1319 -
trunk/WebCore/platform/graphics/win/MediaPlayerPrivateQuickTimeWin.cpp
r44999 r45060 428 428 if (p->paintingDisabled() || !m_qtMovie || m_hasUnsupportedTracks) 429 429 return; 430 431 bool usingTempBitmap = false; 432 OwnPtr<GraphicsContext::WindowsBitmap> bitmap; 430 433 HDC hdc = p->getWindowsContext(r); 434 if (!hdc) { 435 // The graphics context doesn't have an associated HDC so create a temporary 436 // bitmap where QTMovieWin can draw the frame and we can copy it. 437 usingTempBitmap = true; 438 bitmap.set(p->createWindowsBitmap(r.size())); 439 hdc = bitmap->hdc(); 440 441 // FIXME: is this necessary?? 442 XFORM xform; 443 xform.eM11 = 1.0f; 444 xform.eM12 = 0.0f; 445 xform.eM21 = 0.0f; 446 xform.eM22 = 1.0f; 447 xform.eDx = -r.x(); 448 xform.eDy = -r.y(); 449 SetWorldTransform(hdc, &xform); 450 } 451 431 452 m_qtMovie->paint(hdc, r.x(), r.y()); 432 p->releaseWindowsContext(hdc, r); 453 if (usingTempBitmap) 454 p->drawWindowsBitmap(bitmap.get(), r.topLeft()); 455 else 456 p->releaseWindowsContext(hdc, r); 433 457 434 458 #if DRAW_FRAME_RATE … … 542 566 } 543 567 544 } 545 546 #endif 547 568 bool MediaPlayerPrivate::hasSingleSecurityOrigin() const 569 { 570 // We tell quicktime to disallow resources that come from different origins 571 // so we all media is single origin. 572 return true; 573 } 574 575 } 576 577 #endif 578 -
trunk/WebCore/platform/graphics/win/MediaPlayerPrivateQuickTimeWin.h
r44999 r45060 91 91 void paint(GraphicsContext*, const IntRect&); 92 92 93 bool hasSingleSecurityOrigin() const; 93 94 94 95 private:
Note: See TracChangeset
for help on using the changeset viewer.