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

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

Issue 12277023: Define frame subscription interface and implementation on Mac (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: git fetch Created 7 years, 9 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/OpenGL.h> 7 #include <OpenGL/OpenGL.h>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/debug/trace_event.h" 11 #include "base/debug/trace_event.h"
12 #include "base/mac/mac_util.h" 12 #include "base/mac/mac_util.h"
13 #include "base/message_loop.h" 13 #include "base/message_loop.h"
14 #include "base/threading/platform_thread.h" 14 #include "base/threading/platform_thread.h"
15 #include "content/common/content_constants_internal.h" 15 #include "content/common/content_constants_internal.h"
16 #include "content/port/browser/render_widget_host_view_frame_subscriber.h"
16 #include "gpu/command_buffer/service/gpu_switches.h" 17 #include "gpu/command_buffer/service/gpu_switches.h"
17 #include "media/base/video_util.h" 18 #include "media/base/video_util.h"
18 #include "ui/gfx/rect.h" 19 #include "ui/gfx/rect.h"
19 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" 20 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h"
20 #include "ui/gl/gl_context.h" 21 #include "ui/gl/gl_context.h"
21 #include "ui/gl/gl_switches.h" 22 #include "ui/gl/gl_switches.h"
22 #include "ui/gl/gpu_switching_manager.h" 23 #include "ui/gl/gpu_switching_manager.h"
23 #include "ui/gfx/size_conversions.h" 24 #include "ui/gfx/size_conversions.h"
24 #include "ui/surface/io_surface_support_mac.h" 25 #include "ui/surface/io_surface_support_mac.h"
25 26
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 } 342 }
342 343
343 void CompositingIOSurfaceMac::SetIOSurface(uint64 io_surface_handle, 344 void CompositingIOSurfaceMac::SetIOSurface(uint64 io_surface_handle,
344 const gfx::Size& size) { 345 const gfx::Size& size) {
345 pixel_io_surface_size_ = size; 346 pixel_io_surface_size_ = size;
346 CGLSetCurrentContext(cglContext_); 347 CGLSetCurrentContext(cglContext_);
347 MapIOSurfaceToTexture(io_surface_handle); 348 MapIOSurfaceToTexture(io_surface_handle);
348 CGLSetCurrentContext(0); 349 CGLSetCurrentContext(0);
349 } 350 }
350 351
351 void CompositingIOSurfaceMac::DrawIOSurface(NSView* view, float scale_factor) { 352 void CompositingIOSurfaceMac::DrawIOSurface(
353 NSView* view, float scale_factor,
354 RenderWidgetHostViewFrameSubscriber* frame_subscriber) {
352 CGLSetCurrentContext(cglContext_); 355 CGLSetCurrentContext(cglContext_);
353 356
354 bool has_io_surface = MapIOSurfaceToTexture(io_surface_handle_); 357 bool has_io_surface = MapIOSurfaceToTexture(io_surface_handle_);
355 358
356 TRACE_EVENT1("browser", "CompositingIOSurfaceMac::DrawIOSurface", 359 TRACE_EVENT1("browser", "CompositingIOSurfaceMac::DrawIOSurface",
357 "has_io_surface", has_io_surface); 360 "has_io_surface", has_io_surface);
358 361
359 [glContext_ setView:view]; 362 [glContext_ setView:view];
360 gfx::Size window_size(NSSizeToCGSize([view frame].size)); 363 gfx::Size window_size(NSSizeToCGSize([view frame].size));
361 gfx::Size pixel_window_size = gfx::ToFlooredSize( 364 gfx::Size pixel_window_size = gfx::ToFlooredSize(
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 445
443 if (use_glfinish_workaround) { 446 if (use_glfinish_workaround) {
444 TRACE_EVENT0("gpu", "glFinish"); 447 TRACE_EVENT0("gpu", "glFinish");
445 // http://crbug.com/123409 : work around bugs in graphics driver on 448 // http://crbug.com/123409 : work around bugs in graphics driver on
446 // MacBook Air with Intel HD graphics, and possibly on other models, 449 // MacBook Air with Intel HD graphics, and possibly on other models,
447 // by forcing the graphics pipeline to be completely drained at this 450 // by forcing the graphics pipeline to be completely drained at this
448 // point. 451 // point.
449 glFinish(); 452 glFinish();
450 } 453 }
451 454
455 base::Closure copy_done_callback;
456 if (frame_subscriber) {
457 scoped_refptr<media::VideoFrame> frame;
458 RenderWidgetHostViewFrameSubscriber::DeliverFrameCallback callback;
459 bool should_copy = frame_subscriber->ShouldCaptureFrame(&frame, &callback);
460
461 if (should_copy) {
462 copy_done_callback = CopyToVideoFrameInternal(
463 gfx::Rect(io_surface_size_), scale_factor, frame,
464 base::Bind(callback, base::Time::Now()));
465 }
466 }
467
452 CGLFlushDrawable(cglContext_); 468 CGLFlushDrawable(cglContext_);
453 469
454 // For latency_tests.cc: 470 // For latency_tests.cc:
455 UNSHIPPED_TRACE_EVENT_INSTANT0("test_gpu", "CompositorSwapBuffersComplete"); 471 UNSHIPPED_TRACE_EVENT_INSTANT0("test_gpu", "CompositorSwapBuffersComplete");
456 472
457 CGLSetCurrentContext(0); 473 CGLSetCurrentContext(0);
458 474
475 if (!copy_done_callback.is_null())
476 copy_done_callback.Run();
477
459 StartOrContinueDisplayLink(); 478 StartOrContinueDisplayLink();
460 479
461 if (!is_vsync_disabled_) 480 if (!is_vsync_disabled_)
462 RateLimitDraws(); 481 RateLimitDraws();
463 } 482 }
464 483
465 void CompositingIOSurfaceMac::CopyTo( 484 void CompositingIOSurfaceMac::CopyTo(
466 const gfx::Rect& src_pixel_subrect, 485 const gfx::Rect& src_pixel_subrect,
467 float src_scale_factor, 486 float src_scale_factor,
468 const gfx::Size& dst_pixel_size, 487 const gfx::Size& dst_pixel_size,
(...skipping 28 matching lines...) Expand all
497 callback.Run(ret, out); 516 callback.Run(ret, out);
498 } 517 }
499 } 518 }
500 519
501 void CompositingIOSurfaceMac::CopyToVideoFrame( 520 void CompositingIOSurfaceMac::CopyToVideoFrame(
502 const gfx::Rect& requested_src_subrect, 521 const gfx::Rect& requested_src_subrect,
503 float src_scale_factor, 522 float src_scale_factor,
504 const scoped_refptr<media::VideoFrame>& target, 523 const scoped_refptr<media::VideoFrame>& target,
505 const base::Callback<void(bool)>& callback) { 524 const base::Callback<void(bool)>& callback) {
506 CGLSetCurrentContext(cglContext_); 525 CGLSetCurrentContext(cglContext_);
526 base::Closure done_callback = CopyToVideoFrameInternal(requested_src_subrect,
527 src_scale_factor,
528 target, callback);
529 CGLSetCurrentContext(0);
507 530
531 if (done_callback.is_null())
532 return;
533 done_callback.Run();
534 }
535
536 base::Closure CompositingIOSurfaceMac::CopyToVideoFrameInternal(
537 const gfx::Rect& requested_src_subrect,
538 float src_scale_factor,
539 const scoped_refptr<media::VideoFrame>& target,
540 const base::Callback<void(bool)>& callback) {
508 // Using PBO crashes on Intel drivers but not on newer Mountain Lion 541 // Using PBO crashes on Intel drivers but not on newer Mountain Lion
509 // systems. See bug http://crbug.com/152225. 542 // systems. See bug http://crbug.com/152225.
510 const bool async_copy = HasPixelBufferObjectExtension() && 543 const bool async_copy = HasPixelBufferObjectExtension() &&
511 (base::mac::IsOSMountainLionOrLater() || !IsVendorIntel()); 544 (base::mac::IsOSMountainLionOrLater() || !IsVendorIntel());
512 545
513 gfx::Rect region_in_frame = 546 gfx::Rect region_in_frame =
514 media::ComputeLetterboxRegion(gfx::Rect(target->coded_size()), 547 media::ComputeLetterboxRegion(gfx::Rect(target->coded_size()),
515 requested_src_subrect.size()); 548 requested_src_subrect.size());
516 // Make coordinates and sizes even because we letterbox in YUV space right 549 // Make coordinates and sizes even because we letterbox in YUV space right
517 // now (see CopyRGBToVideoFrame). They need to be even for the UV samples to 550 // now (see CopyRGBToVideoFrame). They need to be even for the UV samples to
(...skipping 21 matching lines...) Expand all
539 SkAutoLockPixels bitmap_lock(out); 572 SkAutoLockPixels bitmap_lock(out);
540 media::CopyRGBToVideoFrame( 573 media::CopyRGBToVideoFrame(
541 reinterpret_cast<const uint8*>(out.getPixels()), 574 reinterpret_cast<const uint8*>(out.getPixels()),
542 region_in_frame.width() * 4, 575 region_in_frame.width() * 4,
543 region_in_frame, 576 region_in_frame,
544 target.get()); 577 target.get());
545 ret = true; 578 ret = true;
546 } 579 }
547 } 580 }
548 581
549 CGLSetCurrentContext(0);
550
551 if (!ret) { 582 if (!ret) {
552 VLOG(1) << "Failed to copy IOSurface to video frame, asynchronous mode: " 583 VLOG(1) << "Failed to copy IOSurface to video frame, asynchronous mode: "
553 << async_copy; 584 << async_copy;
554 } 585 }
555 586
556 if (async_copy) { 587 if (async_copy) {
588 // Asynchronous copy failed, return a callback to be executed now.
557 if (!ret) 589 if (!ret)
558 callback.Run(false); 590 return base::Bind(callback, false);
591
592 // Asynchronous copy started, return a null closure.
593 return base::Closure();
559 } else { 594 } else {
560 callback.Run(ret); 595 // Synchronous copy, return a callback to be executed now.
596 return base::Bind(callback, ret);
561 } 597 }
562 } 598 }
563 599
564 bool CompositingIOSurfaceMac::MapIOSurfaceToTexture( 600 bool CompositingIOSurfaceMac::MapIOSurfaceToTexture(
565 uint64 io_surface_handle) { 601 uint64 io_surface_handle) {
566 if (io_surface_.get() && io_surface_handle == io_surface_handle_) 602 if (io_surface_.get() && io_surface_handle == io_surface_handle_)
567 return true; 603 return true;
568 604
569 TRACE_EVENT0("browser", "CompositingIOSurfaceMac::MapIOSurfaceToTexture"); 605 TRACE_EVENT0("browser", "CompositingIOSurfaceMac::MapIOSurfaceToTexture");
570 UnrefIOSurfaceWithContextCurrent(); 606 UnrefIOSurfaceWithContextCurrent();
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after
987 } 1023 }
988 1024
989 gfx::Rect CompositingIOSurfaceMac::IntersectWithIOSurface( 1025 gfx::Rect CompositingIOSurfaceMac::IntersectWithIOSurface(
990 const gfx::Rect& rect, float scale_factor) const { 1026 const gfx::Rect& rect, float scale_factor) const {
991 return gfx::IntersectRects(rect, 1027 return gfx::IntersectRects(rect,
992 gfx::ToEnclosingRect(gfx::ScaleRect(gfx::Rect(io_surface_size_), 1028 gfx::ToEnclosingRect(gfx::ScaleRect(gfx::Rect(io_surface_size_),
993 scale_factor))); 1029 scale_factor)));
994 } 1030 }
995 1031
996 } // namespace content 1032 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698