Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(39)

Unified Diff: webkit/glue/webmediaplayer_impl.cc

Issue 6064007: Allow the creation of a skia::PlatformCanvas from a CGContextRef. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« skia/ext/platform_canvas.h ('K') | « skia/ext/platform_canvas_mac.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webkit/glue/webmediaplayer_impl.cc
diff --git a/webkit/glue/webmediaplayer_impl.cc b/webkit/glue/webmediaplayer_impl.cc
index 4a64b0f71b693404e74fc461ca840a4725767f47..ff0160f8cb326b94ef439cb6e562e99bc9eae69b 100644
--- a/webkit/glue/webmediaplayer_impl.cc
+++ b/webkit/glue/webmediaplayer_impl.cc
@@ -563,55 +563,80 @@ void WebMediaPlayerImpl::paint(WebCanvas* canvas,
#if WEBKIT_USING_SKIA
proxy_->Paint(canvas, rect);
#elif WEBKIT_USING_CG
- // Get the current scaling in X and Y.
- CGAffineTransform mat = CGContextGetCTM(canvas);
- float scale_x = sqrt(mat.a * mat.a + mat.b * mat.b);
- float scale_y = sqrt(mat.c * mat.c + mat.d * mat.d);
- float inverse_scale_x = SkScalarNearlyZero(scale_x) ? 0.0f : 1.0f / scale_x;
- float inverse_scale_y = SkScalarNearlyZero(scale_y) ? 0.0f : 1.0f / scale_y;
- int scaled_width = static_cast<int>(rect.width * fabs(scale_x));
- int scaled_height = static_cast<int>(rect.height * fabs(scale_y));
-
- // Make sure we don't create a huge canvas.
- // TODO(hclam): Respect the aspect ratio.
- if (scaled_width > static_cast<int>(media::Limits::kMaxCanvas))
- scaled_width = media::Limits::kMaxCanvas;
- if (scaled_height > static_cast<int>(media::Limits::kMaxCanvas))
- scaled_height = media::Limits::kMaxCanvas;
-
- // 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() != scaled_width ||
- skia_canvas_->getDevice()->height() != scaled_height) {
- skia_canvas_.reset(
- new skia::PlatformCanvas(scaled_width, scaled_height, true));
- }
+ if (CGBitmapContextGetData(canvas)) {
+ int width = CGBitmapContextGetWidth(canvas);
+ int height = CGBitmapContextGetHeight(canvas);
+ DCHECK(width != 0 && height != 0);
+ skia::PlatformCanvas skia_canvas(width, height, true, canvas);
+
+ // Copy the transformation matrix from the context.
+ CGAffineTransform cgMat = CGContextGetCTM(canvas);
+ SkMatrix skMat;
+ skMat.reset();
+ skMat[SkMatrix::kMScaleX] = cgMat.a;
+ skMat[SkMatrix::kMScaleY] = -cgMat.d;
+ skMat[SkMatrix::kMSkewX] = cgMat.b;
+ skMat[SkMatrix::kMSkewY] = -cgMat.c;
+ skMat[SkMatrix::kMTransX] = cgMat.tx;
+ skMat[SkMatrix::kMTransY] = height - cgMat.ty;
+ skia_canvas.setMatrix(skMat);
+
+ proxy_->Paint(&skia_canvas, rect);
+ } else {
+ // No bitmap context available, so we need to proxy via a bitmap.
+ // TODO(sjl): Can this ever happen?
brettw 2010/12/29 21:03:52 I was wondering the same thing as this todo says.
sjl 2010/12/31 05:55:49 That's my understanding too.
+
+ // Get the current scaling in X and Y.
+ CGAffineTransform mat = CGContextGetCTM(canvas);
+ float scale_x = sqrt(mat.a * mat.a + mat.b * mat.b);
+ float scale_y = sqrt(mat.c * mat.c + mat.d * mat.d);
+ float inverse_scale_x = SkScalarNearlyZero(scale_x) ? 0.0f : 1.0f / scale_x;
+ float inverse_scale_y = SkScalarNearlyZero(scale_y) ? 0.0f : 1.0f / scale_y;
+ int scaled_width = static_cast<int>(rect.width * fabs(scale_x));
+ int scaled_height = static_cast<int>(rect.height * fabs(scale_y));
+
+ // Make sure we don't create a huge canvas.
+ // TODO(hclam): Respect the aspect ratio.
+ if (scaled_width > static_cast<int>(media::Limits::kMaxCanvas))
+ scaled_width = media::Limits::kMaxCanvas;
+ if (scaled_height > static_cast<int>(media::Limits::kMaxCanvas))
+ scaled_height = media::Limits::kMaxCanvas;
+
+ // 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() != scaled_width ||
+ skia_canvas_->getDevice()->height() != scaled_height) {
+ skia_canvas_.reset(
+ new skia::PlatformCanvas(scaled_width, scaled_height, true));
+ }
+
+ // Draw to our temporary skia canvas.
+ gfx::Rect normalized_rect(scaled_width, scaled_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, inverse_scale_x, -inverse_scale_y);
- // Draw to our temporary skia canvas.
- gfx::Rect normalized_rect(scaled_width, scaled_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, inverse_scale_x, -inverse_scale_y);
-
- // 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);
+ // 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
NOTIMPLEMENTED() << "We only support rendering to skia or CG";
#endif
« skia/ext/platform_canvas.h ('K') | « skia/ext/platform_canvas_mac.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698