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