OLD | NEW |
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/threading/platform_thread.h" | 12 #include "base/threading/platform_thread.h" |
13 #include "content/browser/renderer_host/render_widget_host_view_mac.h" | |
14 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
15 #include "gpu/command_buffer/service/gpu_switches.h" | 14 #include "gpu/command_buffer/service/gpu_switches.h" |
16 #include "ui/gfx/rect.h" | 15 #include "ui/gfx/rect.h" |
17 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" | 16 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" |
18 #include "ui/gl/gl_context.h" | 17 #include "ui/gl/gl_context.h" |
19 #include "ui/gl/gl_switches.h" | 18 #include "ui/gl/gl_switches.h" |
20 #include "ui/surface/io_surface_support_mac.h" | 19 #include "ui/surface/io_surface_support_mac.h" |
21 | 20 |
22 #ifdef NDEBUG | 21 #ifdef NDEBUG |
23 #define CHECK_GL_ERROR() | 22 #define CHECK_GL_ERROR() |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 CalculateVsyncParametersLockHeld(&cv_time); | 253 CalculateVsyncParametersLockHeld(&cv_time); |
255 } | 254 } |
256 | 255 |
257 // Stop display link for now, it will be started when needed during Draw. | 256 // Stop display link for now, it will be started when needed during Draw. |
258 StopDisplayLink(); | 257 StopDisplayLink(); |
259 } | 258 } |
260 | 259 |
261 void CompositingIOSurfaceMac::GetVSyncParameters(base::TimeTicks* timebase, | 260 void CompositingIOSurfaceMac::GetVSyncParameters(base::TimeTicks* timebase, |
262 uint32* interval_numerator, | 261 uint32* interval_numerator, |
263 uint32* interval_denominator) { | 262 uint32* interval_denominator) { |
| 263 base::AutoLock lock(lock_); |
264 *timebase = vsync_timebase_; | 264 *timebase = vsync_timebase_; |
265 *interval_numerator = vsync_interval_numerator_; | 265 *interval_numerator = vsync_interval_numerator_; |
266 *interval_denominator = vsync_interval_denominator_; | 266 *interval_denominator = vsync_interval_denominator_; |
267 } | 267 } |
268 | 268 |
269 CompositingIOSurfaceMac::~CompositingIOSurfaceMac() { | 269 CompositingIOSurfaceMac::~CompositingIOSurfaceMac() { |
270 CVDisplayLinkRelease(display_link_); | 270 CVDisplayLinkRelease(display_link_); |
271 UnrefIOSurface(); | 271 UnrefIOSurface(); |
272 } | 272 } |
273 | 273 |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
545 void CompositingIOSurfaceMac::GlobalFrameDidChange() { | 545 void CompositingIOSurfaceMac::GlobalFrameDidChange() { |
546 [glContext_ update]; | 546 [glContext_ update]; |
547 } | 547 } |
548 | 548 |
549 void CompositingIOSurfaceMac::ClearDrawable() { | 549 void CompositingIOSurfaceMac::ClearDrawable() { |
550 [glContext_ clearDrawable]; | 550 [glContext_ clearDrawable]; |
551 UnrefIOSurface(); | 551 UnrefIOSurface(); |
552 } | 552 } |
553 | 553 |
554 void CompositingIOSurfaceMac::DisplayLinkTick(CVDisplayLinkRef display_link, | 554 void CompositingIOSurfaceMac::DisplayLinkTick(CVDisplayLinkRef display_link, |
555 const CVTimeStamp* output_time) { | 555 const CVTimeStamp* time) { |
| 556 TRACE_EVENT0("gpu", "CompositingIOSurfaceMac::DisplayLinkTick"); |
556 base::AutoLock lock(lock_); | 557 base::AutoLock lock(lock_); |
557 // Increment vsync_count but don't let it get ahead of swap_count. | 558 // Increment vsync_count but don't let it get ahead of swap_count. |
558 vsync_count_ = std::min(vsync_count_ + 1, swap_count_); | 559 vsync_count_ = std::min(vsync_count_ + 1, swap_count_); |
559 | 560 |
560 CalculateVsyncParametersLockHeld(output_time); | 561 CalculateVsyncParametersLockHeld(time); |
561 } | 562 } |
562 | 563 |
563 void CompositingIOSurfaceMac::CalculateVsyncParametersLockHeld( | 564 void CompositingIOSurfaceMac::CalculateVsyncParametersLockHeld( |
564 const CVTimeStamp* time) { | 565 const CVTimeStamp* time) { |
| 566 lock_.AssertAcquired(); |
565 vsync_interval_numerator_ = static_cast<uint32>(time->videoRefreshPeriod); | 567 vsync_interval_numerator_ = static_cast<uint32>(time->videoRefreshPeriod); |
566 vsync_interval_denominator_ = time->videoTimeScale; | 568 vsync_interval_denominator_ = time->videoTimeScale; |
567 // Verify that videoRefreshPeriod is 32 bits. | 569 // Verify that videoRefreshPeriod is 32 bits. |
568 DCHECK((time->videoRefreshPeriod & ~0xffffFFFFull) == 0ull); | 570 DCHECK((time->videoRefreshPeriod & ~0xffffFFFFull) == 0ull); |
569 | 571 |
570 vsync_timebase_ = | 572 vsync_timebase_ = |
571 base::TimeTicks::FromInternalValue(time->hostTime / 1000); | 573 base::TimeTicks::FromInternalValue(time->hostTime / 1000); |
572 } | 574 } |
573 | 575 |
574 void CompositingIOSurfaceMac::RateLimitDraws() { | 576 void CompositingIOSurfaceMac::RateLimitDraws() { |
(...skipping 30 matching lines...) Expand all Loading... |
605 } | 607 } |
606 display_link_stop_timer_.Reset(); | 608 display_link_stop_timer_.Reset(); |
607 } | 609 } |
608 | 610 |
609 void CompositingIOSurfaceMac::StopDisplayLink() { | 611 void CompositingIOSurfaceMac::StopDisplayLink() { |
610 if (CVDisplayLinkIsRunning(display_link_)) | 612 if (CVDisplayLinkIsRunning(display_link_)) |
611 CVDisplayLinkStop(display_link_); | 613 CVDisplayLinkStop(display_link_); |
612 } | 614 } |
613 | 615 |
614 } // namespace content | 616 } // namespace content |
OLD | NEW |