summaryrefslogtreecommitdiffstats
path: root/webkit/glue/webmediaplayer_impl.cc
diff options
context:
space:
mode:
authorajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-21 15:21:29 +0000
committerajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-21 15:21:29 +0000
commit776775e2a12012b8747c3f2653140d0cf3036b6c (patch)
tree03cac9870617a3a28eb16975e3d21c0f2a9cefd0 /webkit/glue/webmediaplayer_impl.cc
parent46b44f5d2b5720480d27b9cae607b7b0a078430e (diff)
downloadchromium_src-776775e2a12012b8747c3f2653140d0cf3036b6c.zip
chromium_src-776775e2a12012b8747c3f2653140d0cf3036b6c.tar.gz
chromium_src-776775e2a12012b8747c3f2653140d0cf3036b6c.tar.bz2
Reimplement video painting for mac using CGContext.
This is still a bit hacky. We need to avoid doing the double copy of the bits by making the skia::PlatformCanvas take in a CGContext and use that as its backing store. BUG=19536 TEST=watched at video with it :) Review URL: http://codereview.chromium.org/208039 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@26683 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/glue/webmediaplayer_impl.cc')
-rw-r--r--webkit/glue/webmediaplayer_impl.cc37
1 files changed, 35 insertions, 2 deletions
diff --git a/webkit/glue/webmediaplayer_impl.cc b/webkit/glue/webmediaplayer_impl.cc
index 3b1b298..1369f42 100644
--- a/webkit/glue/webmediaplayer_impl.cc
+++ b/webkit/glue/webmediaplayer_impl.cc
@@ -11,6 +11,7 @@
#include "media/filters/ffmpeg_demuxer.h"
#include "media/filters/ffmpeg_video_decoder.h"
#include "media/filters/null_audio_renderer.h"
+#include "skia/ext/platform_canvas.h"
#include "webkit/api/public/WebRect.h"
#include "webkit/api/public/WebSize.h"
#include "webkit/api/public/WebURL.h"
@@ -435,9 +436,41 @@ void WebMediaPlayerImpl::paint(WebCanvas* canvas,
#if WEBKIT_USING_SKIA
proxy_->Paint(canvas, rect);
+#elif WEBKIT_USING_CG
+ // If there is no preexisting platform canvas, or if the size has
+ // changed, recreate the canvas. This is to avoid recreating the bitmap
+ // buffer over and over for each frame of video.
+ if (!skia_canvas_.get() ||
+ skia_canvas_->getDevice()->width() != rect.width ||
+ skia_canvas_->getDevice()->height() != rect.height) {
+ skia_canvas_.reset(new skia::PlatformCanvas(rect.width, rect.height, true));
+ }
+
+ // Draw to our temporary skia canvas.
+ gfx::Rect normalized_rect(rect.width, rect.height);
+ proxy_->Paint(skia_canvas_.get(), normalized_rect);
+
+ // The mac coordinate system is flipped vertical from the normal skia
+ // coordinates. During painting of the frame, flip the coordinates
+ // system and, for simplicity, also translate the clip rectangle to
+ // start at 0,0.
+ CGContextSaveGState(canvas);
+ CGContextTranslateCTM(canvas, rect.x, rect.height + rect.y);
+ CGContextScaleCTM(canvas, 1.0, -1.0);
+
+ // We need a local variable CGRect version for DrawToContext.
+ CGRect normalized_cgrect =
+ CGRectMake(normalized_rect.x(), normalized_rect.y(),
+ normalized_rect.width(), normalized_rect.height());
+
+ // Copy the frame rendered to our temporary skia canvas onto the passed in
+ // canvas.
+ skia_canvas_->getTopPlatformDevice().DrawToContext(canvas, 0, 0,
+ &normalized_cgrect);
+
+ CGContextRestoreGState(canvas);
#else
- // TODO(darin): Implement this for Mac, where WebCanvas is a CGContext.
- NOTIMPLEMENTED();
+ NOTIMPLEMENTED() << "We only support rendering to skia or CG";
#endif
}