| 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/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
| 13 #include "base/synchronization/lock.h" | 13 #include "base/synchronization/lock.h" |
| 14 #include "base/synchronization/waitable_event.h" | 14 #include "base/synchronization/waitable_event.h" |
| 15 #include "base/time.h" |
| 15 #include "base/win/scoped_comptr.h" | 16 #include "base/win/scoped_comptr.h" |
| 16 #include "ui/gfx/native_widget_types.h" | 17 #include "ui/gfx/native_widget_types.h" |
| 17 #include "ui/gfx/size.h" | 18 #include "ui/gfx/size.h" |
| 18 #include "ui/surface/surface_export.h" | 19 #include "ui/surface/surface_export.h" |
| 19 | 20 |
| 20 class PresentThread; | 21 class PresentThread; |
| 21 | 22 |
| 22 namespace gfx { | 23 namespace gfx { |
| 23 class Rect; | 24 class Rect; |
| 24 } | 25 } |
| 25 | 26 |
| 27 namespace media { |
| 28 class VideoFrame; |
| 29 } |
| 30 |
| 26 class SURFACE_EXPORT AcceleratedPresenter | 31 class SURFACE_EXPORT AcceleratedPresenter |
| 27 : public base::RefCountedThreadSafe<AcceleratedPresenter> { | 32 : public base::RefCountedThreadSafe<AcceleratedPresenter> { |
| 28 public: | 33 public: |
| 29 typedef base::Callback<void(bool, | 34 typedef base::Callback<void(bool, |
| 30 base::TimeTicks, | 35 base::TimeTicks, |
| 31 base::TimeDelta)> CompletionTask; | 36 base::TimeDelta)> CompletionTask; |
| 32 | 37 |
| 33 explicit AcceleratedPresenter(gfx::PluginWindowHandle window); | 38 explicit AcceleratedPresenter(gfx::PluginWindowHandle window); |
| 34 | 39 |
| 35 // Returns a thread safe reference to the presenter for the given window or | 40 // Returns a thread safe reference to the presenter for the given window or |
| (...skipping 22 matching lines...) Expand all Loading... |
| 58 void SetIsSessionLocked(bool locked); | 63 void SetIsSessionLocked(bool locked); |
| 59 | 64 |
| 60 // Schedule the presenter to release its reference to the shared surface. | 65 // Schedule the presenter to release its reference to the shared surface. |
| 61 void ReleaseSurface(); | 66 void ReleaseSurface(); |
| 62 | 67 |
| 63 // The public member functions are called on the main thread. | 68 // The public member functions are called on the main thread. |
| 64 void Present(HDC dc); | 69 void Present(HDC dc); |
| 65 void AsyncCopyTo(const gfx::Rect& src_subrect, | 70 void AsyncCopyTo(const gfx::Rect& src_subrect, |
| 66 const gfx::Size& dst_size, | 71 const gfx::Size& dst_size, |
| 67 const base::Callback<void(bool, const SkBitmap&)>& callback); | 72 const base::Callback<void(bool, const SkBitmap&)>& callback); |
| 73 void AsyncCopyToVideoFrame( |
| 74 const gfx::Rect& src_subrect, |
| 75 const gfx::Size& dst_size, |
| 76 const base::Callback<void(media::VideoFrame*)>& callback); |
| 68 void Invalidate(); | 77 void Invalidate(); |
| 69 | 78 |
| 70 #if defined(USE_AURA) | 79 #if defined(USE_AURA) |
| 71 // TODO(scottmg): This is a temporary hack until we have a two-worlds ash/aura | 80 // TODO(scottmg): This is a temporary hack until we have a two-worlds ash/aura |
| 72 // separation. | 81 // separation. |
| 73 void SetNewTargetWindow(gfx::PluginWindowHandle window); | 82 void SetNewTargetWindow(gfx::PluginWindowHandle window); |
| 74 #endif | 83 #endif |
| 75 | 84 |
| 76 private: | 85 private: |
| 77 friend class base::RefCountedThreadSafe<AcceleratedPresenter>; | 86 friend class base::RefCountedThreadSafe<AcceleratedPresenter>; |
| 78 | 87 |
| 79 ~AcceleratedPresenter(); | 88 ~AcceleratedPresenter(); |
| 80 | 89 |
| 81 // These member functions are called on the PresentThread with which the | 90 // These member functions are called on the PresentThread with which the |
| 82 // presenter has affinity. | 91 // presenter has affinity. |
| 83 void DoPresentAndAcknowledge( | 92 void DoPresentAndAcknowledge( |
| 84 const gfx::Size& size, | 93 const gfx::Size& size, |
| 85 int64 surface_handle, | 94 int64 surface_handle, |
| 86 const CompletionTask& completion_task); | 95 const CompletionTask& completion_task); |
| 87 void DoSuspend(); | 96 void DoSuspend(); |
| 88 void DoPresent(const base::Closure& composite_task); | 97 void DoPresent(const base::Closure& composite_task); |
| 89 void DoReleaseSurface(); | 98 void DoReleaseSurface(); |
| 90 void DoCopyToAndAcknowledge( | 99 void DoCopyToAndAcknowledge( |
| 91 const gfx::Rect& src_subrect, | 100 const gfx::Rect& src_subrect, |
| 92 const gfx::Size& dst_size, | 101 const gfx::Size& dst_size, |
| 93 scoped_refptr<base::SingleThreadTaskRunner> callback_runner, | 102 scoped_refptr<base::SingleThreadTaskRunner> callback_runner, |
| 94 const base::Callback<void(bool, const SkBitmap&)>& callback); | 103 const base::Callback<void(bool, const SkBitmap&)>& callback); |
| 95 bool DoCopyTo(const gfx::Rect& src_subrect, | 104 void DoCopyToVideoFrameAndAcknowledge( |
| 96 const gfx::Size& dst_size, | 105 const gfx::Rect& src_subrect, |
| 97 SkBitmap* bitmap); | 106 const gfx::Size& dst_size, |
| 107 scoped_refptr<base::SingleThreadTaskRunner> callback_runner, |
| 108 const base::Callback<void(media::VideoFrame*)>& callback); |
| 109 bool DoCopyToYUV(const gfx::Rect& src_subrect, |
| 110 const gfx::Size& dst_size, |
| 111 media::VideoFrame* frame); |
| 112 bool DoCopyToARGB(const gfx::Rect& src_subrect, |
| 113 const gfx::Size& dst_size, |
| 114 SkBitmap* bitmap); |
| 98 | 115 |
| 99 void PresentWithGDI(HDC dc); | 116 void PresentWithGDI(HDC dc); |
| 100 gfx::Size GetWindowSize(); | 117 gfx::Size GetWindowSize(); |
| 101 | 118 |
| 102 // This function tries to guess whether Direct3D will be able to reliably | 119 // This function tries to guess whether Direct3D will be able to reliably |
| 103 // present to the window. When the window is resizing, presenting with | 120 // present to the window. When the window is resizing, presenting with |
| 104 // Direct3D causes other regions of the window rendered with GDI to | 121 // Direct3D causes other regions of the window rendered with GDI to |
| 105 // flicker transparent / non-transparent. | 122 // flicker transparent / non-transparent. |
| 106 bool CheckDirect3DWillWork(); | 123 bool CheckDirect3DWillWork(); |
| 107 | 124 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 }; | 175 }; |
| 159 | 176 |
| 160 class SURFACE_EXPORT AcceleratedSurface { | 177 class SURFACE_EXPORT AcceleratedSurface { |
| 161 public: | 178 public: |
| 162 AcceleratedSurface(gfx::PluginWindowHandle window); | 179 AcceleratedSurface(gfx::PluginWindowHandle window); |
| 163 ~AcceleratedSurface(); | 180 ~AcceleratedSurface(); |
| 164 | 181 |
| 165 // Synchronously present a frame with no acknowledgement. | 182 // Synchronously present a frame with no acknowledgement. |
| 166 void Present(HDC dc); | 183 void Present(HDC dc); |
| 167 | 184 |
| 168 // Copies the surface data to |buf|. The copied region is specified with | 185 // Transfer the contents of the surface to an SkBitmap, and invoke a callback |
| 169 // |src_subrect| and the image data is transformed so that it fits in | 186 // with the result. |
| 170 // |dst_size|. | |
| 171 // Caller must ensure that |buf| is allocated with the size no less than | |
| 172 // |4 * dst_size.width() * dst_size.height()| bytes. | |
| 173 void AsyncCopyTo(const gfx::Rect& src_subrect, | 187 void AsyncCopyTo(const gfx::Rect& src_subrect, |
| 174 const gfx::Size& dst_size, | 188 const gfx::Size& dst_size, |
| 175 const base::Callback<void(bool, const SkBitmap&)>& callback); | 189 const base::Callback<void(bool, const SkBitmap&)>& callback); |
| 190 // Transfer the contents of the surface to a YV12 VideoFrame, and invoke a |
| 191 // callback with the result. |
| 192 void AsyncCopyToVideoFrame( |
| 193 const gfx::Rect& src_subrect, |
| 194 const gfx::Size& dst_size, |
| 195 const base::Callback<void(media::VideoFrame*)>& callback); |
| 176 | 196 |
| 177 // Temporarily release resources until a new surface is asynchronously | 197 // Temporarily release resources until a new surface is asynchronously |
| 178 // presented. Present will not be able to represent the last surface after | 198 // presented. Present will not be able to represent the last surface after |
| 179 // calling this and will return false. | 199 // calling this and will return false. |
| 180 void Suspend(); | 200 void Suspend(); |
| 181 | 201 |
| 182 // Indicates that the surface has become invisible. | 202 // Indicates that the surface has become invisible. |
| 183 void WasHidden(); | 203 void WasHidden(); |
| 184 | 204 |
| 185 // Called when the Windows session in locked or unlocked. | 205 // Called when the Windows session in locked or unlocked. |
| 186 void SetIsSessionLocked(bool locked); | 206 void SetIsSessionLocked(bool locked); |
| 187 | 207 |
| 188 private: | 208 private: |
| 189 const scoped_refptr<AcceleratedPresenter> presenter_; | 209 const scoped_refptr<AcceleratedPresenter> presenter_; |
| 190 DISALLOW_COPY_AND_ASSIGN(AcceleratedSurface); | 210 DISALLOW_COPY_AND_ASSIGN(AcceleratedSurface); |
| 191 }; | 211 }; |
| 192 | 212 |
| 193 #endif // UI_SURFACE_ACCELERATED_SURFACE_WIN_H_ | 213 #endif // UI_SURFACE_ACCELERATED_SURFACE_WIN_H_ |
| OLD | NEW |