Commit 33e9cda3 authored by apatrick@chromium.org's avatar apatrick@chromium.org

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
parent 5eab39e3
......@@ -187,6 +187,8 @@ bool GpuProcessHostUIShim::OnControlMessageReceived(
OnAcceleratedSurfaceBuffersSwapped)
IPC_MESSAGE_HANDLER(GpuHostMsg_AcceleratedSurfacePostSubBuffer,
OnAcceleratedSurfacePostSubBuffer)
IPC_MESSAGE_HANDLER(GpuHostMsg_AcceleratedSurfaceSuspend,
OnAcceleratedSurfaceSuspend)
IPC_MESSAGE_HANDLER(GpuHostMsg_GraphicsInfoCollected,
OnGraphicsInfoCollected)
......@@ -371,6 +373,17 @@ void GpuProcessHostUIShim::OnAcceleratedSurfacePostSubBuffer(
view->AcceleratedSurfacePostSubBuffer(params, host_id_);
}
void GpuProcessHostUIShim::OnAcceleratedSurfaceSuspend(int32 surface_id) {
TRACE_EVENT0("renderer",
"GpuProcessHostUIShim::OnAcceleratedSurfaceSuspend");
RenderWidgetHostView* view = GetRenderWidgetHostViewFromSurfaceID(surface_id);
if (!view)
return;
view->AcceleratedSurfaceSuspend();
}
#if defined(UI_COMPOSITOR_IMAGE_TRANSPORT)
void GpuProcessHostUIShim::OnAcceleratedSurfaceRelease(
......
......@@ -94,6 +94,7 @@ class GpuProcessHostUIShim
const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params);
void OnAcceleratedSurfacePostSubBuffer(
const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params);
void OnAcceleratedSurfaceSuspend(int32 surface_id);
#if defined(OS_MACOSX) || defined(UI_COMPOSITOR_IMAGE_TRANSPORT)
void OnAcceleratedSurfaceNew(
......
......@@ -224,6 +224,10 @@ class RenderWidgetHostView {
const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params,
int gpu_host_id) = 0;
// Release the accelerated surface temporarily. It will be recreated on the
// next swap buffers or post sub buffer.
virtual void AcceleratedSurfaceSuspend() = 0;
#if defined(OS_MACOSX)
// Tells the view whether or not to accept first responder status. If |flag|
// is true, the view does not accept first responder status and instead
......
......@@ -429,6 +429,9 @@ void RenderWidgetHostViewAura::AcceleratedSurfacePostSubBuffer(
#endif
}
void RenderWidgetHostViewAura::AcceleratedSurfaceSuspend() {
}
#if defined(UI_COMPOSITOR_IMAGE_TRANSPORT)
void RenderWidgetHostViewAura::AcceleratedSurfaceNew(
int32 width,
......
......@@ -94,6 +94,7 @@ class CONTENT_EXPORT RenderWidgetHostViewAura
virtual void AcceleratedSurfacePostSubBuffer(
const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params,
int gpu_host_id) OVERRIDE;
virtual void AcceleratedSurfaceSuspend() OVERRIDE;
#if defined(UI_COMPOSITOR_IMAGE_TRANSPORT)
virtual void AcceleratedSurfaceNew(
int32 width,
......
......@@ -1023,6 +1023,10 @@ void RenderWidgetHostViewGtk::AcceleratedSurfacePostSubBuffer(
RenderWidgetHost::AcknowledgePostSubBuffer(params.route_id, gpu_host_id);
}
void RenderWidgetHostViewGtk::AcceleratedSurfaceSuspend() {
}
void RenderWidgetHostViewGtk::SetBackground(const SkBitmap& background) {
RenderWidgetHostView::SetBackground(background);
host_->Send(new ViewMsg_SetBackground(host_->routing_id(), background));
......
......@@ -98,6 +98,7 @@ class CONTENT_EXPORT RenderWidgetHostViewGtk : public RenderWidgetHostView {
virtual void AcceleratedSurfacePostSubBuffer(
const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params,
int gpu_host_id) OVERRIDE;
virtual void AcceleratedSurfaceSuspend() OVERRIDE;
virtual void SetBackground(const SkBitmap& background) OVERRIDE;
virtual void CreatePluginContainer(gfx::PluginWindowHandle id) OVERRIDE;
virtual void DestroyPluginContainer(gfx::PluginWindowHandle id) OVERRIDE;
......
......@@ -264,6 +264,7 @@ class RenderWidgetHostViewMac : public RenderWidgetHostView {
virtual void AcceleratedSurfacePostSubBuffer(
const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params,
int gpu_host_id) OVERRIDE;
virtual void AcceleratedSurfaceSuspend() OVERRIDE;
virtual void GetScreenInfo(WebKit::WebScreenInfo* results) OVERRIDE;
virtual gfx::Rect GetRootWindowBounds() OVERRIDE;
virtual gfx::PluginWindowHandle GetCompositingSurface() OVERRIDE;
......
......@@ -934,6 +934,9 @@ void RenderWidgetHostViewMac::AcceleratedSurfacePostSubBuffer(
}
}
void RenderWidgetHostViewMac::AcceleratedSurfaceSuspend() {
}
void RenderWidgetHostViewMac::UpdateRootGpuViewVisibility(
bool show_gpu_widget) {
TRACE_EVENT1("renderer_host",
......
......@@ -2140,6 +2140,13 @@ void RenderWidgetHostViewWin::AcceleratedSurfacePostSubBuffer(
RenderWidgetHost::AcknowledgePostSubBuffer(params.route_id, gpu_host_id);
}
void RenderWidgetHostViewWin::AcceleratedSurfaceSuspend() {
if (!accelerated_surface_.get())
return;
accelerated_surface_->Suspend();
}
void RenderWidgetHostViewWin::SetAccessibilityFocus(int acc_obj_id) {
if (!render_widget_host_)
return;
......
......@@ -205,6 +205,7 @@ class RenderWidgetHostViewWin
virtual void AcceleratedSurfacePostSubBuffer(
const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params,
int gpu_host_id) OVERRIDE;
virtual void AcceleratedSurfaceSuspend() OVERRIDE;
virtual void OnAccessibilityNotifications(
const std::vector<ViewHostMsg_AccessibilityNotification_Params>& params
) OVERRIDE;
......
......@@ -222,6 +222,9 @@ void TestRenderWidgetHostView::AcceleratedSurfacePostSubBuffer(
int gpu_host_id) {
}
void TestRenderWidgetHostView::AcceleratedSurfaceSuspend() {
}
#if defined(OS_MACOSX)
gfx::Rect TestRenderWidgetHostView::GetViewCocoaBounds() const {
......
......@@ -102,6 +102,7 @@ class TestRenderWidgetHostView : public RenderWidgetHostView {
virtual void AcceleratedSurfacePostSubBuffer(
const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params,
int gpu_host_id) OVERRIDE;
virtual void AcceleratedSurfaceSuspend() OVERRIDE;
#if defined(OS_MACOSX)
virtual void SetTakesFocusOnlyOnMouseDown(bool flag) OVERRIDE {}
virtual gfx::Rect GetViewCocoaBounds() const OVERRIDE;
......
......@@ -251,6 +251,11 @@ IPC_MESSAGE_CONTROL1(GpuHostMsg_AcceleratedSurfacePostSubBuffer,
IPC_MESSAGE_CONTROL1(GpuHostMsg_AcceleratedSurfaceRelease,
GpuHostMsg_AcceleratedSurfaceRelease_Params)
// Tells the browser to release resources for the given surface until the next
// time swap buffers or post sub buffer is sent.
IPC_MESSAGE_CONTROL1(GpuHostMsg_AcceleratedSurfaceSuspend,
int32 /* surface_id */)
//------------------------------------------------------------------------------
// GPU Channel Messages
// These are messages from a renderer process to the GPU process.
......
......@@ -172,6 +172,10 @@ bool ImageTransportHelper::MakeCurrent() {
return decoder->MakeCurrent();
}
void ImageTransportHelper::Suspend() {
manager_->Send(new GpuHostMsg_AcceleratedSurfaceSuspend(stub_->surface_id()));
}
gpu::GpuScheduler* ImageTransportHelper::Scheduler() {
if (!stub_.get())
return NULL;
......
......@@ -109,6 +109,8 @@ class ImageTransportHelper : public IPC::Channel::Listener {
// Make the surface's context current.
bool MakeCurrent();
void Suspend();
private:
gpu::GpuScheduler* Scheduler();
gpu::gles2::GLES2Decoder* Decoder();
......
......@@ -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();
}
......@@ -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<AcceleratedPresenter> presenter_;
DISALLOW_COPY_AND_ASSIGN(AcceleratedSurface);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment