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

Side by Side Diff: content/browser/renderer_host/compositing_iosurface_mac.mm

Issue 15689003: Part 3/3 (RWH/IOSurface) of adding with device scale factor to transport surfaces (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add missed lines Created 7 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
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 "content/browser/renderer_host/compositing_iosurface_mac.h" 5 #include "content/browser/renderer_host/compositing_iosurface_mac.h"
6 6
7 #include <OpenGL/CGLRenderers.h> 7 #include <OpenGL/CGLRenderers.h>
8 #include <OpenGL/OpenGL.h> 8 #include <OpenGL/OpenGL.h>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 // Having two NSOpenGLContexts bound to an NSView concurrently will cause 328 // Having two NSOpenGLContexts bound to an NSView concurrently will cause
329 // artifacts and crashes. If |context_| is bound to |view|, then unbind 329 // artifacts and crashes. If |context_| is bound to |view|, then unbind
330 // |context_| before |new_context| gets bound to |view|. 330 // |context_| before |new_context| gets bound to |view|.
331 // http://crbug.com/230883 331 // http://crbug.com/230883
332 if ([context_->nsgl_context() view] == view) 332 if ([context_->nsgl_context() view] == view)
333 [context_->nsgl_context() clearDrawable]; 333 [context_->nsgl_context() clearDrawable];
334 334
335 context_ = new_context; 335 context_ = new_context;
336 } 336 }
337 337
338 void CompositingIOSurfaceMac::SetDeviceScaleFactor(float scale_factor) {
339 // TODO: After a resolution change, the DPI-ness of the view and the
340 // IOSurface might not be in sync.
341 io_surface_size_ = gfx::ToFlooredSize(
342 gfx::ScaleSize(pixel_io_surface_size_, 1.0 / scale_factor));
343 }
344
345 bool CompositingIOSurfaceMac::is_vsync_disabled() const { 338 bool CompositingIOSurfaceMac::is_vsync_disabled() const {
346 return context_->is_vsync_disabled(); 339 return context_->is_vsync_disabled();
347 } 340 }
348 341
349 void CompositingIOSurfaceMac::GetVSyncParameters(base::TimeTicks* timebase, 342 void CompositingIOSurfaceMac::GetVSyncParameters(base::TimeTicks* timebase,
350 uint32* interval_numerator, 343 uint32* interval_numerator,
351 uint32* interval_denominator) { 344 uint32* interval_denominator) {
352 base::AutoLock lock(lock_); 345 base::AutoLock lock(lock_);
353 *timebase = vsync_timebase_; 346 *timebase = vsync_timebase_;
354 *interval_numerator = vsync_interval_numerator_; 347 *interval_numerator = vsync_interval_numerator_;
355 *interval_denominator = vsync_interval_denominator_; 348 *interval_denominator = vsync_interval_denominator_;
356 } 349 }
357 350
358 CompositingIOSurfaceMac::~CompositingIOSurfaceMac() { 351 CompositingIOSurfaceMac::~CompositingIOSurfaceMac() {
359 FailAllCopies(); 352 FailAllCopies();
360 CVDisplayLinkRelease(display_link_); 353 CVDisplayLinkRelease(display_link_);
361 CGLSetCurrentContext(context_->cgl_context()); 354 CGLSetCurrentContext(context_->cgl_context());
362 DestroyAllCopyContextsWithinContext(); 355 DestroyAllCopyContextsWithinContext();
363 UnrefIOSurfaceWithContextCurrent(); 356 UnrefIOSurfaceWithContextCurrent();
364 CGLSetCurrentContext(0); 357 CGLSetCurrentContext(0);
365 context_ = nil; 358 context_ = nil;
366 } 359 }
367 360
368 void CompositingIOSurfaceMac::SetIOSurface(uint64 io_surface_handle, 361 void CompositingIOSurfaceMac::SetIOSurface(uint64 io_surface_handle,
369 const gfx::Size& size) { 362 const gfx::Size& size,
363 float scale_factor) {
370 pixel_io_surface_size_ = size; 364 pixel_io_surface_size_ = size;
365 dip_io_surface_size_ = gfx::ToFlooredSize(
366 gfx::ScaleSize(pixel_io_surface_size_, 1.0 / scale_factor));
371 CGLSetCurrentContext(context_->cgl_context()); 367 CGLSetCurrentContext(context_->cgl_context());
372 MapIOSurfaceToTexture(io_surface_handle); 368 MapIOSurfaceToTexture(io_surface_handle);
373 CGLSetCurrentContext(0); 369 CGLSetCurrentContext(0);
374 } 370 }
375 371
376 int CompositingIOSurfaceMac::GetRendererID() { 372 int CompositingIOSurfaceMac::GetRendererID() {
377 GLint current_renderer_id = -1; 373 GLint current_renderer_id = -1;
378 if (CGLGetParameter(context_->cgl_context(), 374 if (CGLGetParameter(context_->cgl_context(),
379 kCGLCPCurrentRendererID, 375 kCGLCPCurrentRendererID,
380 &current_renderer_id) == kCGLNoError) 376 &current_renderer_id) == kCGLNoError)
(...skipping 19 matching lines...) Expand all
400 396
401 TRACE_EVENT1("browser", "CompositingIOSurfaceMac::DrawIOSurface", 397 TRACE_EVENT1("browser", "CompositingIOSurfaceMac::DrawIOSurface",
402 "has_io_surface", has_io_surface); 398 "has_io_surface", has_io_surface);
403 399
404 [context_->nsgl_context() setView:view]; 400 [context_->nsgl_context() setView:view];
405 gfx::Size window_size(NSSizeToCGSize([view frame].size)); 401 gfx::Size window_size(NSSizeToCGSize([view frame].size));
406 gfx::Size pixel_window_size = gfx::ToFlooredSize( 402 gfx::Size pixel_window_size = gfx::ToFlooredSize(
407 gfx::ScaleSize(window_size, scale_factor)); 403 gfx::ScaleSize(window_size, scale_factor));
408 glViewport(0, 0, pixel_window_size.width(), pixel_window_size.height()); 404 glViewport(0, 0, pixel_window_size.width(), pixel_window_size.height());
409 405
410 SetDeviceScaleFactor(scale_factor);
411
412 SurfaceQuad quad; 406 SurfaceQuad quad;
413 quad.set_size(io_surface_size_, pixel_io_surface_size_); 407 quad.set_size(dip_io_surface_size_, pixel_io_surface_size_);
414 408
415 glMatrixMode(GL_PROJECTION); 409 glMatrixMode(GL_PROJECTION);
416 glLoadIdentity(); 410 glLoadIdentity();
417 411
418 // Note that the projection keeps things in view units, so the use of 412 // Note that the projection keeps things in view units, so the use of
419 // window_size / io_surface_size_ (as opposed to the pixel_ variants) below is 413 // window_size / dip_io_surface_size_ (as opposed to the pixel_ variants)
420 // correct. 414 // below is correct.
421 glOrtho(0, window_size.width(), window_size.height(), 0, -1, 1); 415 glOrtho(0, window_size.width(), window_size.height(), 0, -1, 1);
422 glMatrixMode(GL_MODELVIEW); 416 glMatrixMode(GL_MODELVIEW);
423 glLoadIdentity(); 417 glLoadIdentity();
424 418
425 glDisable(GL_DEPTH_TEST); 419 glDisable(GL_DEPTH_TEST);
426 glDisable(GL_BLEND); 420 glDisable(GL_BLEND);
427 421
428 if (has_io_surface) { 422 if (has_io_surface) {
429 context_->shader_program_cache()->UseBlitProgram(); 423 context_->shader_program_cache()->UseBlitProgram();
430 glActiveTexture(GL_TEXTURE0); 424 glActiveTexture(GL_TEXTURE0);
431 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, texture_); 425 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, texture_);
432 426
433 DrawQuad(quad); 427 DrawQuad(quad);
434 428
435 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0); CHECK_GL_ERROR(); 429 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0); CHECK_GL_ERROR();
436 430
437 // Fill the resize gutters with white. 431 // Fill the resize gutters with white.
438 if (window_size.width() > io_surface_size_.width() || 432 if (window_size.width() > dip_io_surface_size_.width() ||
439 window_size.height() > io_surface_size_.height()) { 433 window_size.height() > dip_io_surface_size_.height()) {
440 context_->shader_program_cache()->UseSolidWhiteProgram(); 434 context_->shader_program_cache()->UseSolidWhiteProgram();
441 SurfaceQuad filler_quad; 435 SurfaceQuad filler_quad;
442 if (window_size.width() > io_surface_size_.width()) { 436 if (window_size.width() > dip_io_surface_size_.width()) {
443 // Draw right-side gutter down to the bottom of the window. 437 // Draw right-side gutter down to the bottom of the window.
444 filler_quad.set_rect(io_surface_size_.width(), 0.0f, 438 filler_quad.set_rect(dip_io_surface_size_.width(), 0.0f,
445 window_size.width(), window_size.height()); 439 window_size.width(), window_size.height());
446 DrawQuad(filler_quad); 440 DrawQuad(filler_quad);
447 } 441 }
448 if (window_size.height() > io_surface_size_.height()) { 442 if (window_size.height() > dip_io_surface_size_.height()) {
449 // Draw bottom gutter to the width of the IOSurface. 443 // Draw bottom gutter to the width of the IOSurface.
450 filler_quad.set_rect(0.0f, io_surface_size_.height(), 444 filler_quad.set_rect(
451 io_surface_size_.width(), window_size.height()); 445 0.0f, dip_io_surface_size_.height(),
446 dip_io_surface_size_.width(), window_size.height());
452 DrawQuad(filler_quad); 447 DrawQuad(filler_quad);
453 } 448 }
454 } 449 }
455 450
456 // Workaround for issue 158469. Issue a dummy draw call with texture_ not 451 // Workaround for issue 158469. Issue a dummy draw call with texture_ not
457 // bound to blit_rgb_sampler_location_, in order to shake all references 452 // bound to blit_rgb_sampler_location_, in order to shake all references
458 // to the IOSurface out of the driver. 453 // to the IOSurface out of the driver.
459 glBegin(GL_TRIANGLES); 454 glBegin(GL_TRIANGLES);
460 glEnd(); 455 glEnd();
461 456
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 glFinish(); 488 glFinish();
494 } 489 }
495 490
496 base::Closure copy_done_callback; 491 base::Closure copy_done_callback;
497 if (frame_subscriber) { 492 if (frame_subscriber) {
498 const base::Time present_time = base::Time::Now(); 493 const base::Time present_time = base::Time::Now();
499 scoped_refptr<media::VideoFrame> frame; 494 scoped_refptr<media::VideoFrame> frame;
500 RenderWidgetHostViewFrameSubscriber::DeliverFrameCallback callback; 495 RenderWidgetHostViewFrameSubscriber::DeliverFrameCallback callback;
501 if (frame_subscriber->ShouldCaptureFrame(present_time, &frame, &callback)) { 496 if (frame_subscriber->ShouldCaptureFrame(present_time, &frame, &callback)) {
502 copy_done_callback = CopyToVideoFrameWithinContext( 497 copy_done_callback = CopyToVideoFrameWithinContext(
503 gfx::Rect(pixel_io_surface_size_), scale_factor, true, frame, 498 gfx::Rect(pixel_io_surface_size_), true, frame,
504 base::Bind(callback, present_time)); 499 base::Bind(callback, present_time));
505 } 500 }
506 } 501 }
507 502
508 CGLFlushDrawable(context_->cgl_context()); 503 CGLFlushDrawable(context_->cgl_context());
509 504
510 // For latency_tests.cc: 505 // For latency_tests.cc:
511 UNSHIPPED_TRACE_EVENT_INSTANT0("test_gpu", "CompositorSwapBuffersComplete", 506 UNSHIPPED_TRACE_EVENT_INSTANT0("test_gpu", "CompositorSwapBuffersComplete",
512 TRACE_EVENT_SCOPE_THREAD); 507 TRACE_EVENT_SCOPE_THREAD);
513 508
514 // Try to finish previous copy requests after flush to get better pipelining. 509 // Try to finish previous copy requests after flush to get better pipelining.
515 std::vector<base::Closure> copy_done_callbacks; 510 std::vector<base::Closure> copy_done_callbacks;
516 FinishAllCopiesWithinContext(&copy_done_callbacks); 511 FinishAllCopiesWithinContext(&copy_done_callbacks);
517 512
518 CGLSetCurrentContext(0); 513 CGLSetCurrentContext(0);
519 514
520 if (!copy_done_callback.is_null()) 515 if (!copy_done_callback.is_null())
521 copy_done_callbacks.push_back(copy_done_callback); 516 copy_done_callbacks.push_back(copy_done_callback);
522 for (size_t i = 0; i < copy_done_callbacks.size(); ++i) 517 for (size_t i = 0; i < copy_done_callbacks.size(); ++i)
523 copy_done_callbacks[i].Run(); 518 copy_done_callbacks[i].Run();
524 519
525 StartOrContinueDisplayLink(); 520 StartOrContinueDisplayLink();
526 521
527 if (!is_vsync_disabled()) 522 if (!is_vsync_disabled())
528 RateLimitDraws(); 523 RateLimitDraws();
529 } 524 }
530 525
531 void CompositingIOSurfaceMac::CopyTo( 526 void CompositingIOSurfaceMac::CopyTo(
532 const gfx::Rect& src_pixel_subrect, 527 const gfx::Rect& src_pixel_subrect,
533 float src_scale_factor,
534 const gfx::Size& dst_pixel_size, 528 const gfx::Size& dst_pixel_size,
535 const base::Callback<void(bool, const SkBitmap&)>& callback) { 529 const base::Callback<void(bool, const SkBitmap&)>& callback) {
536 scoped_ptr<SkBitmap> output(new SkBitmap()); 530 scoped_ptr<SkBitmap> output(new SkBitmap());
537 output->setConfig(SkBitmap::kARGB_8888_Config, 531 output->setConfig(SkBitmap::kARGB_8888_Config,
538 dst_pixel_size.width(), dst_pixel_size.height()); 532 dst_pixel_size.width(), dst_pixel_size.height());
539 if (!output->allocPixels()) { 533 if (!output->allocPixels()) {
540 DLOG(ERROR) << "Failed to allocate SkBitmap pixels!"; 534 DLOG(ERROR) << "Failed to allocate SkBitmap pixels!";
541 callback.Run(false, *output); 535 callback.Run(false, *output);
542 return; 536 return;
543 } 537 }
544 DCHECK_EQ(output->rowBytesAsPixels(), dst_pixel_size.width()) 538 DCHECK_EQ(output->rowBytesAsPixels(), dst_pixel_size.width())
545 << "Stride is required to be equal to width for GPU readback."; 539 << "Stride is required to be equal to width for GPU readback.";
546 output->setIsOpaque(true); 540 output->setIsOpaque(true);
547 541
548 CGLSetCurrentContext(context_->cgl_context()); 542 CGLSetCurrentContext(context_->cgl_context());
549 const base::Closure copy_done_callback = CopyToSelectedOutputWithinContext( 543 const base::Closure copy_done_callback = CopyToSelectedOutputWithinContext(
550 src_pixel_subrect, src_scale_factor, gfx::Rect(dst_pixel_size), false, 544 src_pixel_subrect, gfx::Rect(dst_pixel_size), false,
551 output.get(), NULL, 545 output.get(), NULL,
552 base::Bind(&ReverseArgumentOrder, callback, base::Passed(&output))); 546 base::Bind(&ReverseArgumentOrder, callback, base::Passed(&output)));
553 CGLSetCurrentContext(0); 547 CGLSetCurrentContext(0);
554 if (!copy_done_callback.is_null()) 548 if (!copy_done_callback.is_null())
555 copy_done_callback.Run(); 549 copy_done_callback.Run();
556 } 550 }
557 551
558 void CompositingIOSurfaceMac::CopyToVideoFrame( 552 void CompositingIOSurfaceMac::CopyToVideoFrame(
559 const gfx::Rect& src_pixel_subrect, 553 const gfx::Rect& src_pixel_subrect,
560 float src_scale_factor,
561 const scoped_refptr<media::VideoFrame>& target, 554 const scoped_refptr<media::VideoFrame>& target,
562 const base::Callback<void(bool)>& callback) { 555 const base::Callback<void(bool)>& callback) {
563 CGLSetCurrentContext(context_->cgl_context()); 556 CGLSetCurrentContext(context_->cgl_context());
564 const base::Closure copy_done_callback = CopyToVideoFrameWithinContext( 557 const base::Closure copy_done_callback = CopyToVideoFrameWithinContext(
565 src_pixel_subrect, src_scale_factor, false, target, callback); 558 src_pixel_subrect, false, target, callback);
566 CGLSetCurrentContext(0); 559 CGLSetCurrentContext(0);
567 if (!copy_done_callback.is_null()) 560 if (!copy_done_callback.is_null())
568 copy_done_callback.Run(); 561 copy_done_callback.Run();
569 } 562 }
570 563
571 base::Closure CompositingIOSurfaceMac::CopyToVideoFrameWithinContext( 564 base::Closure CompositingIOSurfaceMac::CopyToVideoFrameWithinContext(
572 const gfx::Rect& src_pixel_subrect, 565 const gfx::Rect& src_pixel_subrect,
573 float src_scale_factor,
574 bool called_within_draw, 566 bool called_within_draw,
575 const scoped_refptr<media::VideoFrame>& target, 567 const scoped_refptr<media::VideoFrame>& target,
576 const base::Callback<void(bool)>& callback) { 568 const base::Callback<void(bool)>& callback) {
577 gfx::Rect region_in_frame = media::ComputeLetterboxRegion( 569 gfx::Rect region_in_frame = media::ComputeLetterboxRegion(
578 gfx::Rect(target->coded_size()), src_pixel_subrect.size()); 570 gfx::Rect(target->coded_size()), src_pixel_subrect.size());
579 // Make coordinates and sizes even because we letterbox in YUV space right 571 // Make coordinates and sizes even because we letterbox in YUV space right
580 // now (see CopyRGBToVideoFrame). They need to be even for the UV samples to 572 // now (see CopyRGBToVideoFrame). They need to be even for the UV samples to
581 // line up correctly. 573 // line up correctly.
582 region_in_frame = gfx::Rect(region_in_frame.x() & ~1, 574 region_in_frame = gfx::Rect(region_in_frame.x() & ~1,
583 region_in_frame.y() & ~1, 575 region_in_frame.y() & ~1,
584 region_in_frame.width() & ~1, 576 region_in_frame.width() & ~1,
585 region_in_frame.height() & ~1); 577 region_in_frame.height() & ~1);
586 DCHECK(!region_in_frame.IsEmpty()); 578 DCHECK(!region_in_frame.IsEmpty());
587 DCHECK_LE(region_in_frame.right(), target->coded_size().width()); 579 DCHECK_LE(region_in_frame.right(), target->coded_size().width());
588 DCHECK_LE(region_in_frame.bottom(), target->coded_size().height()); 580 DCHECK_LE(region_in_frame.bottom(), target->coded_size().height());
589 581
590 return CopyToSelectedOutputWithinContext( 582 return CopyToSelectedOutputWithinContext(
591 src_pixel_subrect, src_scale_factor, region_in_frame, called_within_draw, 583 src_pixel_subrect, region_in_frame, called_within_draw,
592 NULL, target, callback); 584 NULL, target, callback);
593 } 585 }
594 586
595 bool CompositingIOSurfaceMac::MapIOSurfaceToTexture( 587 bool CompositingIOSurfaceMac::MapIOSurfaceToTexture(
596 uint64 io_surface_handle) { 588 uint64 io_surface_handle) {
597 if (io_surface_.get() && io_surface_handle == io_surface_handle_) 589 if (io_surface_.get() && io_surface_handle == io_surface_handle_)
598 return true; 590 return true;
599 591
600 TRACE_EVENT0("browser", "CompositingIOSurfaceMac::MapIOSurfaceToTexture"); 592 TRACE_EVENT0("browser", "CompositingIOSurfaceMac::MapIOSurfaceToTexture");
601 UnrefIOSurfaceWithContextCurrent(); 593 UnrefIOSurfaceWithContextCurrent();
602 594
603 io_surface_.reset(io_surface_support_->IOSurfaceLookup( 595 io_surface_.reset(io_surface_support_->IOSurfaceLookup(
604 static_cast<uint32>(io_surface_handle))); 596 static_cast<uint32>(io_surface_handle)));
605 // Can fail if IOSurface with that ID was already released by the gpu 597 // Can fail if IOSurface with that ID was already released by the gpu
606 // process. 598 // process.
607 if (!io_surface_) { 599 if (!io_surface_) {
608 io_surface_handle_ = 0; 600 io_surface_handle_ = 0;
609 return false; 601 return false;
610 } 602 }
611 603
612 io_surface_handle_ = io_surface_handle; 604 io_surface_handle_ = io_surface_handle;
613 605
614 // Actual IOSurface size is rounded up to reduce reallocations during window 606 // Actual IOSurface size is rounded up to reduce reallocations during window
615 // resize. Get the actual size to properly map the texture. 607 // resize. Get the actual size to properly map the texture.
616 gfx::Size rounded_size( 608 gfx::Size rounded_size(
617 io_surface_support_->IOSurfaceGetWidth(io_surface_), 609 io_surface_support_->IOSurfaceGetWidth(io_surface_),
618 io_surface_support_->IOSurfaceGetHeight(io_surface_)); 610 io_surface_support_->IOSurfaceGetHeight(io_surface_));
619 611
620 // TODO(thakis): Keep track of the view size over IPC. At the moment,
621 // the correct view units are computed on first paint.
622 io_surface_size_ = pixel_io_surface_size_;
623
624 GLenum target = GL_TEXTURE_RECTANGLE_ARB; 612 GLenum target = GL_TEXTURE_RECTANGLE_ARB;
625 glGenTextures(1, &texture_); 613 glGenTextures(1, &texture_);
626 glBindTexture(target, texture_); 614 glBindTexture(target, texture_);
627 glTexParameterf(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 615 glTexParameterf(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
628 glTexParameterf(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); CHECK_GL_ERROR(); 616 glTexParameterf(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); CHECK_GL_ERROR();
629 GLuint plane = 0; 617 GLuint plane = 0;
630 CGLError cglerror = io_surface_support_->CGLTexImageIOSurface2D( 618 CGLError cglerror = io_surface_support_->CGLTexImageIOSurface2D(
631 context_->cgl_context(), 619 context_->cgl_context(),
632 target, 620 target,
633 GL_RGBA, 621 GL_RGBA,
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
775 const bool forced_synchronous = CommandLine::ForCurrentProcess()->HasSwitch( 763 const bool forced_synchronous = CommandLine::ForCurrentProcess()->HasSwitch(
776 switches::kForceSynchronousGLReadPixels); 764 switches::kForceSynchronousGLReadPixels);
777 return (!forced_synchronous && 765 return (!forced_synchronous &&
778 HasAppleFenceExtension() && 766 HasAppleFenceExtension() &&
779 HasPixelBufferObjectExtension() && 767 HasPixelBufferObjectExtension() &&
780 (base::mac::IsOSMountainLionOrLater() || !IsVendorIntel())); 768 (base::mac::IsOSMountainLionOrLater() || !IsVendorIntel()));
781 } 769 }
782 770
783 base::Closure CompositingIOSurfaceMac::CopyToSelectedOutputWithinContext( 771 base::Closure CompositingIOSurfaceMac::CopyToSelectedOutputWithinContext(
784 const gfx::Rect& src_pixel_subrect, 772 const gfx::Rect& src_pixel_subrect,
785 float src_scale_factor,
786 const gfx::Rect& dst_pixel_rect, 773 const gfx::Rect& dst_pixel_rect,
787 bool called_within_draw, 774 bool called_within_draw,
788 const SkBitmap* bitmap_output, 775 const SkBitmap* bitmap_output,
789 const scoped_refptr<media::VideoFrame>& video_frame_output, 776 const scoped_refptr<media::VideoFrame>& video_frame_output,
790 const base::Callback<void(bool)>& done_callback) { 777 const base::Callback<void(bool)>& done_callback) {
791 DCHECK_NE(bitmap_output != NULL, video_frame_output != NULL); 778 DCHECK_NE(bitmap_output != NULL, video_frame_output != NULL);
792 DCHECK(!done_callback.is_null()); 779 DCHECK(!done_callback.is_null());
793 780
794 const bool async_copy = IsAsynchronousReadbackSupported(); 781 const bool async_copy = IsAsynchronousReadbackSupported();
795 TRACE_EVENT2( 782 TRACE_EVENT2(
(...skipping 16 matching lines...) Expand all
812 } else { 799 } else {
813 copy_context = copy_context_pool_.back(); 800 copy_context = copy_context_pool_.back();
814 copy_context_pool_.pop_back(); 801 copy_context_pool_.pop_back();
815 } 802 }
816 803
817 // Set up source texture, bound to the GL_TEXTURE_RECTANGLE_ARB target. 804 // Set up source texture, bound to the GL_TEXTURE_RECTANGLE_ARB target.
818 if (!MapIOSurfaceToTexture(io_surface_handle_)) 805 if (!MapIOSurfaceToTexture(io_surface_handle_))
819 return base::Bind(done_callback, false); 806 return base::Bind(done_callback, false);
820 807
821 // Send transform commands to the GPU. 808 // Send transform commands to the GPU.
822 const gfx::Rect src_rect = IntersectWithIOSurface(src_pixel_subrect, 809 const gfx::Rect src_rect = IntersectWithIOSurface(src_pixel_subrect);
823 src_scale_factor);
824 copy_context->num_outputs = 0; 810 copy_context->num_outputs = 0;
825 if (bitmap_output) { 811 if (bitmap_output) {
826 if (copy_context->transformer->ResizeBilinear( 812 if (copy_context->transformer->ResizeBilinear(
827 texture_, src_rect, dst_pixel_rect.size(), 813 texture_, src_rect, dst_pixel_rect.size(),
828 &copy_context->output_textures[0])) { 814 &copy_context->output_textures[0])) {
829 copy_context->num_outputs = 1; 815 copy_context->num_outputs = 1;
830 copy_context->output_texture_sizes[0] = dst_pixel_rect.size(); 816 copy_context->output_texture_sizes[0] = dst_pixel_rect.size();
831 } 817 }
832 } else { 818 } else {
833 if (copy_context->transformer->TransformRGBToYV12( 819 if (copy_context->transformer->TransformRGBToYV12(
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
1067 copy_requests_.begin(), copy_requests_.end()); 1053 copy_requests_.begin(), copy_requests_.end());
1068 copy_requests_.clear(); 1054 copy_requests_.clear();
1069 while (!copy_context_pool_.empty()) { 1055 while (!copy_context_pool_.empty()) {
1070 scoped_ptr<CopyContext> copy_context(copy_context_pool_.back()); 1056 scoped_ptr<CopyContext> copy_context(copy_context_pool_.back());
1071 copy_context_pool_.pop_back(); 1057 copy_context_pool_.pop_back();
1072 copy_context->ReleaseCachedGLObjects(); 1058 copy_context->ReleaseCachedGLObjects();
1073 } 1059 }
1074 } 1060 }
1075 1061
1076 gfx::Rect CompositingIOSurfaceMac::IntersectWithIOSurface( 1062 gfx::Rect CompositingIOSurfaceMac::IntersectWithIOSurface(
1077 const gfx::Rect& rect, float scale_factor) const { 1063 const gfx::Rect& rect) const {
1078 return gfx::IntersectRects(rect, 1064 return gfx::IntersectRects(rect,
1079 gfx::ToEnclosingRect(gfx::ScaleRect(gfx::Rect(io_surface_size_), 1065 gfx::ToEnclosingRect(gfx::Rect(pixel_io_surface_size_)));
1080 scale_factor)));
1081 } 1066 }
1082 1067
1083 } // namespace content 1068 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698