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 #ifndef UI_SURFACE_ACCELERATED_SURFACE_WIN_H_ | 5 #ifndef UI_SURFACE_ACCELERATED_SURFACE_WIN_H_ |
6 #define UI_SURFACE_ACCELERATED_SURFACE_WIN_H_ | 6 #define UI_SURFACE_ACCELERATED_SURFACE_WIN_H_ |
7 | 7 |
8 #include <d3d9.h> | 8 #include <d3d9.h> |
9 | 9 |
10 #include "base/callback_forward.h" | 10 #include "base/callback_forward.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/synchronization/lock.h" | 12 #include "base/synchronization/lock.h" |
13 #include "base/synchronization/waitable_event.h" | 13 #include "base/synchronization/waitable_event.h" |
14 #include "base/win/scoped_comptr.h" | 14 #include "base/win/scoped_comptr.h" |
15 #include "ui/gfx/native_widget_types.h" | 15 #include "ui/gfx/native_widget_types.h" |
16 #include "ui/gfx/size.h" | 16 #include "ui/gfx/size.h" |
17 #include "ui/surface/surface_export.h" | 17 #include "ui/surface/surface_export.h" |
18 | 18 |
19 class PresentThread; | 19 class PresentThread; |
20 | 20 |
21 namespace gfx { | 21 namespace gfx { |
22 class Rect; | 22 class Rect; |
23 } | 23 } |
24 | 24 |
25 class SURFACE_EXPORT AcceleratedPresenter | 25 class SURFACE_EXPORT AcceleratedPresenter |
26 : public base::RefCountedThreadSafe<AcceleratedPresenter> { | 26 : public base::RefCountedThreadSafe<AcceleratedPresenter> { |
27 public: | 27 public: |
28 typedef base::Callback<void(bool)> CompletionTaskl; | 28 typedef base::Callback<void(bool, |
| 29 base::TimeTicks, |
| 30 base::TimeDelta)> CompletionTask; |
29 | 31 |
30 explicit AcceleratedPresenter(gfx::NativeWindow window); | 32 explicit AcceleratedPresenter(gfx::NativeWindow window); |
31 | 33 |
32 // Returns a thread safe reference to the presenter for the given window or | 34 // Returns a thread safe reference to the presenter for the given window or |
33 // null is no such presenter exists. The thread safe refptr ensures the | 35 // null is no such presenter exists. The thread safe refptr ensures the |
34 // presenter will not be destroyed. This can be called on any thread. | 36 // presenter will not be destroyed. This can be called on any thread. |
35 static scoped_refptr<AcceleratedPresenter> GetForWindow( | 37 static scoped_refptr<AcceleratedPresenter> GetForWindow( |
36 gfx::NativeWindow window); | 38 gfx::NativeWindow window); |
37 | 39 |
38 // Schedule a frame to be presented. The completion callback will be invoked | 40 // Schedule a frame to be presented. The completion callback will be invoked |
39 // when it is safe to write to the surface on another thread. The lock for | 41 // when it is safe to write to the surface on another thread. The lock for |
40 // this surface will be held while the completion callback runs. This can be | 42 // this surface will be held while the completion callback runs. This can be |
41 // called on any thread. | 43 // called on any thread. |
42 void AsyncPresentAndAcknowledge( | 44 void AsyncPresentAndAcknowledge( |
43 const gfx::Size& size, | 45 const gfx::Size& size, |
44 int64 surface_handle, | 46 int64 surface_handle, |
45 const base::Callback<void(bool)>& completion_task); | 47 const CompletionTask& completion_task); |
46 | 48 |
47 // Schedule the presenter to free all its resources. This can be called on any | 49 // Schedule the presenter to free all its resources. This can be called on any |
48 // thread. | 50 // thread. |
49 void Suspend(); | 51 void Suspend(); |
50 | 52 |
51 // Indicates that the presenter has become invisible. | 53 // Indicates that the presenter has become invisible. |
52 void WasHidden(); | 54 void WasHidden(); |
53 | 55 |
54 // Schedule the presenter to release its reference to the shared surface. | 56 // Schedule the presenter to release its reference to the shared surface. |
55 void ReleaseSurface(); | 57 void ReleaseSurface(); |
56 | 58 |
57 // The public member functions are called on the main thread. | 59 // The public member functions are called on the main thread. |
58 bool Present(HDC dc); | 60 bool Present(HDC dc); |
59 bool CopyTo(const gfx::Rect& src_subrect, | 61 bool CopyTo(const gfx::Rect& src_subrect, |
60 const gfx::Size& dst_size, | 62 const gfx::Size& dst_size, |
61 void* buf); | 63 void* buf); |
62 void Invalidate(); | 64 void Invalidate(); |
63 | 65 |
64 private: | 66 private: |
65 friend class base::RefCountedThreadSafe<AcceleratedPresenter>; | 67 friend class base::RefCountedThreadSafe<AcceleratedPresenter>; |
66 | 68 |
67 ~AcceleratedPresenter(); | 69 ~AcceleratedPresenter(); |
68 | 70 |
69 // These member functions are called on the PresentThread with which the | 71 // These member functions are called on the PresentThread with which the |
70 // presenter has affinity. | 72 // presenter has affinity. |
71 void DoPresentAndAcknowledge( | 73 void DoPresentAndAcknowledge( |
72 const gfx::Size& size, | 74 const gfx::Size& size, |
73 int64 surface_handle, | 75 int64 surface_handle, |
74 const base::Callback<void(bool)>& completion_task); | 76 const CompletionTask& completion_task); |
75 void DoSuspend(); | 77 void DoSuspend(); |
76 void DoPresent(HDC dc, bool* presented); | 78 void DoPresent(HDC dc, bool* presented); |
77 bool DoRealPresent(HDC dc); | 79 bool DoRealPresent(HDC dc); |
78 void DoReleaseSurface(); | 80 void DoReleaseSurface(); |
79 | 81 |
80 // This gets the timestamp and period of the display's last vsync. | 82 // This gets the timestamp and period of the display's last vsync. |
81 // The period is represented as a ratio which, when divided, will give you | 83 // The period is represented as a ratio which, when divided, will give you |
82 // the interval in seconds. i.e.: | 84 // the interval in seconds. i.e.: |
83 // inteval_in_seconds = interval_numerator / interval_denominator; | 85 // inteval_in_seconds = interval_numerator / interval_denominator; |
84 // For example, some machines will return an interval_numerator of 1001 | 86 // For example, some machines will return an interval_numerator of 1001 |
85 // and an interval_denominator of 60000, resulting in an interval of | 87 // and an interval_denominator of 60000, resulting in an interval of |
86 // 1001/60000 ~= .016683 seconds | 88 // 1001/60000 ~= .016683 seconds |
87 // Note: This function assumes lock_ is acquired. | 89 // Note: This function assumes lock_ is acquired. |
88 void GetPresentationStats(base::TimeTicks* timebase, | 90 // Returns true on success. |
| 91 bool GetPresentationStats(base::TimeTicks* timebase, |
89 uint32* interval_numerator, | 92 uint32* interval_numerator, |
90 uint32* interval_denominator); | 93 uint32* interval_denominator); |
91 | 94 |
92 // The thread with which this presenter has affinity. | 95 // The thread with which this presenter has affinity. |
93 PresentThread* const present_thread_; | 96 PresentThread* const present_thread_; |
94 | 97 |
95 // The window that is presented to. | 98 // The window that is presented to. |
96 gfx::NativeWindow window_; | 99 gfx::NativeWindow window_; |
97 | 100 |
98 // The lock is taken while any thread is calling the object, except those that | 101 // The lock is taken while any thread is calling the object, except those that |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 | 152 |
150 // Indicates that the surface has become invisible. | 153 // Indicates that the surface has become invisible. |
151 void WasHidden(); | 154 void WasHidden(); |
152 | 155 |
153 private: | 156 private: |
154 const scoped_refptr<AcceleratedPresenter> presenter_; | 157 const scoped_refptr<AcceleratedPresenter> presenter_; |
155 DISALLOW_COPY_AND_ASSIGN(AcceleratedSurface); | 158 DISALLOW_COPY_AND_ASSIGN(AcceleratedSurface); |
156 }; | 159 }; |
157 | 160 |
158 #endif // UI_SURFACE_ACCELERATED_SURFACE_WIN_H_ | 161 #endif // UI_SURFACE_ACCELERATED_SURFACE_WIN_H_ |
OLD | NEW |