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

Side by Side Diff: ui/surface/accelerated_surface_win.cc

Issue 27710005: cc: Use HighResNow as timebase if it is fast and reliable (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fix DCHECK Created 7 years, 1 month 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
« no previous file with comments | « ui/gl/gl_surface_win.cc ('k') | no next file » | 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 "ui/surface/accelerated_surface_win.h" 5 #include "ui/surface/accelerated_surface_win.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 #include <algorithm> 8 #include <algorithm>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 10 matching lines...) Expand all
21 #include "base/strings/stringprintf.h" 21 #include "base/strings/stringprintf.h"
22 #include "base/synchronization/waitable_event.h" 22 #include "base/synchronization/waitable_event.h"
23 #include "base/threading/thread.h" 23 #include "base/threading/thread.h"
24 #include "base/threading/thread_restrictions.h" 24 #include "base/threading/thread_restrictions.h"
25 #include "base/win/wrapped_window_proc.h" 25 #include "base/win/wrapped_window_proc.h"
26 #include "media/base/video_frame.h" 26 #include "media/base/video_frame.h"
27 #include "media/base/video_util.h" 27 #include "media/base/video_util.h"
28 #include "third_party/skia/include/core/SkBitmap.h" 28 #include "third_party/skia/include/core/SkBitmap.h"
29 #include "ui/base/win/shell.h" 29 #include "ui/base/win/shell.h"
30 #include "ui/events/latency_info.h" 30 #include "ui/events/latency_info.h"
31 #include "ui/gfx/frame_time.h"
31 #include "ui/gfx/rect.h" 32 #include "ui/gfx/rect.h"
32 #include "ui/gfx/win/dpi.h" 33 #include "ui/gfx/win/dpi.h"
33 #include "ui/gfx/win/hwnd_util.h" 34 #include "ui/gfx/win/hwnd_util.h"
34 #include "ui/gl/gl_switches.h" 35 #include "ui/gl/gl_switches.h"
35 #include "ui/surface/accelerated_surface_transformer_win.h" 36 #include "ui/surface/accelerated_surface_transformer_win.h"
36 #include "ui/surface/d3d9_utils_win.h" 37 #include "ui/surface/d3d9_utils_win.h"
37 #include "ui/surface/surface_switches.h" 38 #include "ui/surface/surface_switches.h"
38 39
39 namespace d3d_utils = ui_surface_d3d9_utils; 40 namespace d3d_utils = ui_surface_d3d9_utils;
40 41
(...skipping 829 matching lines...) Expand 10 before | Expand all | Expand 10 after
870 871
871 // I can't figure out how to determine how many scanlines are in the 872 // I can't figure out how to determine how many scanlines are in the
872 // vertical blank so clamp it such that scanline / height <= 1. 873 // vertical blank so clamp it such that scanline / height <= 1.
873 int clamped_scanline = std::min(raster_status.ScanLine, display_mode.Height); 874 int clamped_scanline = std::min(raster_status.ScanLine, display_mode.Height);
874 875
875 // The Internet says that on some GPUs, the scanline is not available 876 // The Internet says that on some GPUs, the scanline is not available
876 // while in the vertical blank. 877 // while in the vertical blank.
877 if (raster_status.InVBlank) 878 if (raster_status.InVBlank)
878 clamped_scanline = display_mode.Height; 879 clamped_scanline = display_mode.Height;
879 880
880 base::TimeTicks current_time = base::TimeTicks::HighResNow();
881
882 // Figure out approximately how far back in time the last vsync was based on 881 // Figure out approximately how far back in time the last vsync was based on
883 // the ratio of the raster scanline to the display height. 882 // the ratio of the raster scanline to the display height.
884 base::TimeTicks last_vsync_time; 883 base::TimeTicks last_vsync_time;
885 base::TimeDelta refresh_period; 884 base::TimeDelta refresh_period;
885
886 if (display_mode.Height) { 886 if (display_mode.Height) {
887 refresh_period = base::TimeDelta::FromMicroseconds(
888 1000000 / display_mode.RefreshRate);
889 // If FrameTime is not high resolution, we use a timebase of zero to avoid
890 // introducing jitter into our frame start times.
891 if (gfx::FrameTime::TimestampsAreHighRes()) {
892 base::TimeTicks current_time = gfx::FrameTime::Now();
887 last_vsync_time = current_time - 893 last_vsync_time = current_time -
888 base::TimeDelta::FromMilliseconds((clamped_scanline * 1000) / 894 base::TimeDelta::FromMilliseconds((clamped_scanline * 1000) /
889 (display_mode.RefreshRate * display_mode.Height)); 895 (display_mode.RefreshRate * display_mode.Height));
890 refresh_period = base::TimeDelta::FromMicroseconds( 896 }
891 1000000 / display_mode.RefreshRate);
892 } 897 }
893 898
894 // Wait for the StretchRect to complete before notifying the GPU process 899 // Wait for the StretchRect to complete before notifying the GPU process
895 // that it is safe to write to its backing store again. 900 // that it is safe to write to its backing store again.
896 { 901 {
897 TRACE_EVENT0("gpu", "spin"); 902 TRACE_EVENT0("gpu", "spin");
898 903
899 do { 904 do {
900 hr = present_thread_->query()->GetData(NULL, 0, D3DGETDATA_FLUSH); 905 hr = present_thread_->query()->GetData(NULL, 0, D3DGETDATA_FLUSH);
901 if (hr == S_FALSE) { 906 if (hr == S_FALSE) {
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
1094 presenter_->Suspend(); 1099 presenter_->Suspend();
1095 } 1100 }
1096 1101
1097 void AcceleratedSurface::WasHidden() { 1102 void AcceleratedSurface::WasHidden() {
1098 presenter_->WasHidden(); 1103 presenter_->WasHidden();
1099 } 1104 }
1100 1105
1101 void AcceleratedSurface::SetIsSessionLocked(bool locked) { 1106 void AcceleratedSurface::SetIsSessionLocked(bool locked) {
1102 presenter_->SetIsSessionLocked(locked); 1107 presenter_->SetIsSessionLocked(locked);
1103 } 1108 }
OLDNEW
« no previous file with comments | « ui/gl/gl_surface_win.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698