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

Side by Side Diff: webkit/media/webmediaplayer_impl.cc

Issue 10392018: remove WEBKIT_USING_CG (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 7 months 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « webkit/media/webmediaplayer_impl.h ('k') | webkit/plugins/ppapi/ppapi_plugin_instance.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "webkit/media/webmediaplayer_impl.h" 5 #include "webkit/media/webmediaplayer_impl.h"
6 6
7 #include <limits> 7 #include <limits>
8 #include <string> 8 #include <string>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 const WebKit::WebRect& rect) { 500 const WebKit::WebRect& rect) {
501 paint(canvas, rect, 0xFF); 501 paint(canvas, rect, 0xFF);
502 } 502 }
503 503
504 void WebMediaPlayerImpl::paint(WebCanvas* canvas, 504 void WebMediaPlayerImpl::paint(WebCanvas* canvas,
505 const WebRect& rect, 505 const WebRect& rect,
506 uint8_t alpha) { 506 uint8_t alpha) {
507 DCHECK_EQ(main_loop_, MessageLoop::current()); 507 DCHECK_EQ(main_loop_, MessageLoop::current());
508 DCHECK(proxy_); 508 DCHECK(proxy_);
509 509
510 #if WEBKIT_USING_SKIA
511 proxy_->Paint(canvas, rect, alpha); 510 proxy_->Paint(canvas, rect, alpha);
512 #elif WEBKIT_USING_CG
513 // Get the current scaling in X and Y.
514 CGAffineTransform mat = CGContextGetCTM(canvas);
515 float scale_x = sqrt(mat.a * mat.a + mat.b * mat.b);
516 float scale_y = sqrt(mat.c * mat.c + mat.d * mat.d);
517 float inverse_scale_x = SkScalarNearlyZero(scale_x) ? 0.0f : 1.0f / scale_x;
518 float inverse_scale_y = SkScalarNearlyZero(scale_y) ? 0.0f : 1.0f / scale_y;
519 int scaled_width = static_cast<int>(rect.width * fabs(scale_x));
520 int scaled_height = static_cast<int>(rect.height * fabs(scale_y));
521
522 // Make sure we don't create a huge canvas.
523 // TODO(hclam): Respect the aspect ratio.
524 if (scaled_width > static_cast<int>(media::limits::kMaxCanvas))
525 scaled_width = media::limits::kMaxCanvas;
526 if (scaled_height > static_cast<int>(media::limits::kMaxCanvas))
527 scaled_height = media::limits::kMaxCanvas;
528
529 // If there is no preexisting platform canvas, or if the size has
530 // changed, recreate the canvas. This is to avoid recreating the bitmap
531 // buffer over and over for each frame of video.
532 if (!skia_canvas_.get() ||
533 skia_canvas_->getDevice()->width() != scaled_width ||
534 skia_canvas_->getDevice()->height() != scaled_height) {
535 skia_canvas_.reset(
536 new skia::PlatformCanvas(scaled_width, scaled_height, true));
537 }
538
539 // Draw to our temporary skia canvas.
540 gfx::Rect normalized_rect(scaled_width, scaled_height);
541 proxy_->Paint(skia_canvas_.get(), normalized_rect);
542
543 // The mac coordinate system is flipped vertical from the normal skia
544 // coordinates. During painting of the frame, flip the coordinates
545 // system and, for simplicity, also translate the clip rectangle to
546 // start at 0,0.
547 CGContextSaveGState(canvas);
548 CGContextTranslateCTM(canvas, rect.x, rect.height + rect.y);
549 CGContextScaleCTM(canvas, inverse_scale_x, -inverse_scale_y);
550
551 // We need a local variable CGRect version for DrawToContext.
552 CGRect normalized_cgrect =
553 CGRectMake(normalized_rect.x(), normalized_rect.y(),
554 normalized_rect.width(), normalized_rect.height());
555
556 // Copy the frame rendered to our temporary skia canvas onto the passed in
557 // canvas.
558 skia::DrawToNativeContext(skia_canvas_.get(), canvas, 0, 0,
559 &normalized_cgrect);
560
561 CGContextRestoreGState(canvas);
562 #else
563 NOTIMPLEMENTED() << "We only support rendering to skia or CG";
564 #endif
565 } 511 }
566 512
567 bool WebMediaPlayerImpl::hasSingleSecurityOrigin() const { 513 bool WebMediaPlayerImpl::hasSingleSecurityOrigin() const {
568 if (proxy_) 514 if (proxy_)
569 return proxy_->HasSingleOrigin(); 515 return proxy_->HasSingleOrigin();
570 return true; 516 return true;
571 } 517 }
572 518
573 WebMediaPlayer::MovieLoadType WebMediaPlayerImpl::movieLoadType() const { 519 WebMediaPlayer::MovieLoadType WebMediaPlayerImpl::movieLoadType() const {
574 DCHECK_EQ(main_loop_, MessageLoop::current()); 520 DCHECK_EQ(main_loop_, MessageLoop::current());
(...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after
1062 return audio_source_provider_; 1008 return audio_source_provider_;
1063 } 1009 }
1064 1010
1065 void WebMediaPlayerImpl::IncrementExternallyAllocatedMemory() { 1011 void WebMediaPlayerImpl::IncrementExternallyAllocatedMemory() {
1066 DCHECK_EQ(main_loop_, MessageLoop::current()); 1012 DCHECK_EQ(main_loop_, MessageLoop::current());
1067 incremented_externally_allocated_memory_ = true; 1013 incremented_externally_allocated_memory_ = true;
1068 v8::V8::AdjustAmountOfExternalAllocatedMemory(kPlayerExtraMemory); 1014 v8::V8::AdjustAmountOfExternalAllocatedMemory(kPlayerExtraMemory);
1069 } 1015 }
1070 1016
1071 } // namespace webkit_media 1017 } // namespace webkit_media
OLDNEW
« no previous file with comments | « webkit/media/webmediaplayer_impl.h ('k') | webkit/plugins/ppapi/ppapi_plugin_instance.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698