summaryrefslogtreecommitdiffstats
path: root/ui/gfx/surface
diff options
context:
space:
mode:
authorjbauman@chromium.org <jbauman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-07 03:10:13 +0000
committerjbauman@chromium.org <jbauman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-07 03:10:13 +0000
commitfe8a0ce9d56facded166efad6ca4607d4df71893 (patch)
treece225617864abda2f4407a813c3aa7e64ca5aa3b /ui/gfx/surface
parentb572ed45ad620f93f372b81019c3d5275f85b7a4 (diff)
downloadchromium_src-fe8a0ce9d56facded166efad6ca4607d4df71893.zip
chromium_src-fe8a0ce9d56facded166efad6ca4607d4df71893.tar.gz
chromium_src-fe8a0ce9d56facded166efad6ca4607d4df71893.tar.bz2
Cache shared texture in browser
Doing CreateTexture every frame seems to cause a leak in the NVIDIA driver on some optimus systems, so instead cache the texture while it exists. BUG=115422 TEST= Review URL: http://codereview.chromium.org/10007024 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@131245 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/gfx/surface')
-rw-r--r--ui/gfx/surface/accelerated_surface_win.cc19
-rw-r--r--ui/gfx/surface/accelerated_surface_win.h7
2 files changed, 22 insertions, 4 deletions
diff --git a/ui/gfx/surface/accelerated_surface_win.cc b/ui/gfx/surface/accelerated_surface_win.cc
index 9ab6bb4..7b9991b 100644
--- a/ui/gfx/surface/accelerated_surface_win.cc
+++ b/ui/gfx/surface/accelerated_surface_win.cc
@@ -472,6 +472,13 @@ void AcceleratedPresenter::Suspend() {
this));
}
+void AcceleratedPresenter::ReleaseSurface() {
+ present_thread_->message_loop()->PostTask(
+ FROM_HERE,
+ base::Bind(&AcceleratedPresenter::DoReleaseSurface,
+ this));
+}
+
void AcceleratedPresenter::Invalidate() {
// Make any pending or future presentation tasks do nothing. Once the last
// last pending task has been ignored, the reference count on the presenter
@@ -554,8 +561,7 @@ void AcceleratedPresenter::DoPresentAndAcknowledge(
return;
}
- base::win::ScopedComPtr<IDirect3DTexture9> source_texture;
- {
+ if (!source_texture_.get()) {
TRACE_EVENT0("surface", "CreateTexture");
HANDLE handle = reinterpret_cast<HANDLE>(surface_handle);
hr = present_thread_->device()->CreateTexture(size.width(),
@@ -564,14 +570,14 @@ void AcceleratedPresenter::DoPresentAndAcknowledge(
D3DUSAGE_RENDERTARGET,
D3DFMT_A8R8G8B8,
D3DPOOL_DEFAULT,
- source_texture.Receive(),
+ source_texture_.Receive(),
&handle);
if (FAILED(hr))
return;
}
base::win::ScopedComPtr<IDirect3DSurface9> source_surface;
- hr = source_texture->GetSurfaceLevel(0, source_surface.Receive());
+ hr = source_texture_->GetSurfaceLevel(0, source_surface.Receive());
if (FAILED(hr))
return;
@@ -650,6 +656,11 @@ void AcceleratedPresenter::DoSuspend() {
swap_chain_ = NULL;
}
+void AcceleratedPresenter::DoReleaseSurface() {
+ base::AutoLock locked(lock_);
+ source_texture_.Release();
+}
+
AcceleratedSurface::AcceleratedSurface(gfx::NativeWindow window)
: presenter_(g_accelerated_presenter_map.Pointer()->CreatePresenter(
window)) {
diff --git a/ui/gfx/surface/accelerated_surface_win.h b/ui/gfx/surface/accelerated_surface_win.h
index 32f7acf..8a8da98 100644
--- a/ui/gfx/surface/accelerated_surface_win.h
+++ b/ui/gfx/surface/accelerated_surface_win.h
@@ -45,6 +45,9 @@ class SURFACE_EXPORT AcceleratedPresenter
// thread.
void Suspend();
+ // Schedule the presenter to release its reference to the shared surface.
+ void ReleaseSurface();
+
// The public member functions are called on the main thread.
bool Present();
bool CopyTo(const gfx::Size& size, void* buf);
@@ -64,6 +67,7 @@ class SURFACE_EXPORT AcceleratedPresenter
void DoSuspend();
void DoPresent(bool* presented);
bool DoRealPresent();
+ void DoReleaseSurface();
// The thread with which this presenter has affinity.
PresentThread* const present_thread_;
@@ -83,6 +87,9 @@ class SURFACE_EXPORT AcceleratedPresenter
// with which the surface has affinity.
gfx::Size size_;
+ // This is a shared texture that is being presented from.
+ base::win::ScopedComPtr<IDirect3DTexture9> source_texture_;
+
// The swap chain is presented to the child window. Copy semantics
// are used so it is possible to represent it to quickly validate the window.
base::win::ScopedComPtr<IDirect3DSwapChain9> swap_chain_;