From 33e9cda3cdc7dfa6c0787814512fb6b42b0ff408 Mon Sep 17 00:00:00 2001 From: "apatrick@chromium.org" Date: Tue, 31 Jan 2012 22:57:49 +0000 Subject: Add IPC allowing GPU process to tell browser process to temporarily drop a front buffer. This is to conserve video memory for hidden tabs that are not expected to be needed in the near term. Review URL: https://chromiumcodereview.appspot.com/9303009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@119979 0039d316-1c4b-4281-b951-d872f2087c98 --- ui/gfx/surface/accelerated_surface_win.cc | 17 +++++++++++++++++ ui/gfx/surface/accelerated_surface_win.h | 5 +++++ 2 files changed, 22 insertions(+) (limited to 'ui/gfx/surface') diff --git a/ui/gfx/surface/accelerated_surface_win.cc b/ui/gfx/surface/accelerated_surface_win.cc index c5c93c2..45fdf48 100644 --- a/ui/gfx/surface/accelerated_surface_win.cc +++ b/ui/gfx/surface/accelerated_surface_win.cc @@ -122,6 +122,10 @@ class AcceleratedPresenter { const int thread_affinity_; base::ScopedNativeLibrary d3d_module_; + // Whether the presenter is suspended and therefore unable to represent. Only + // accessed on the UI thread so the lock is unnecessary. + bool suspended_; + // The size of the swap chain once any pending resizes have been processed. // Only accessed on the UI thread so the lock is unnecessary. gfx::Size pending_size_; @@ -151,6 +155,7 @@ class AcceleratedPresenter { AcceleratedPresenter::AcceleratedPresenter() : thread_affinity_(g_present_thread_pool.Pointer()->NextThread()), + suspended_(true), num_pending_resizes_(0) { g_present_thread_pool.Pointer()->PostTask( thread_affinity_, @@ -196,6 +201,8 @@ void AcceleratedPresenter::AsyncPresentAndAcknowledge( size, surface_id, completion_task)); + + suspended_ = false; } bool AcceleratedPresenter::Present(gfx::NativeWindow window) { @@ -203,6 +210,9 @@ bool AcceleratedPresenter::Present(gfx::NativeWindow window) { HRESULT hr; + if (suspended_) + return false; + base::AutoLock locked(lock_); if (!device_) @@ -265,6 +275,8 @@ void AcceleratedPresenter::Suspend() { base::Bind(&AcceleratedPresenter::DoResize, base::Unretained(this), gfx::Size(1, 1))); + + suspended_ = true; } void AcceleratedPresenter::DoInitialize() { @@ -499,3 +511,8 @@ void AcceleratedSurface::AsyncPresentAndAcknowledge( bool AcceleratedSurface::Present(HWND window) { return presenter_->Present(window); } + +void AcceleratedSurface::Suspend() { + presenter_->Suspend(); +} + diff --git a/ui/gfx/surface/accelerated_surface_win.h b/ui/gfx/surface/accelerated_surface_win.h index a2b6c66..cf59178 100644 --- a/ui/gfx/surface/accelerated_surface_win.h +++ b/ui/gfx/surface/accelerated_surface_win.h @@ -30,6 +30,11 @@ class SURFACE_EXPORT AcceleratedSurface { // Synchronously present a frame with no acknowledgement. bool Present(HWND window); + // Temporarily release resources until a new surface is asynchronously + // presented. Present will not be able to represent the last surface after + // calling this and will return false. + void Suspend(); + private: linked_ptr presenter_; DISALLOW_COPY_AND_ASSIGN(AcceleratedSurface); -- cgit v1.1