1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "content/browser/aura/browser_compositor_output_surface_proxy.h" 6 7 #include "base/bind.h" 8 #include "content/browser/aura/browser_compositor_output_surface.h" 9 #include "content/browser/gpu/browser_gpu_channel_host_factory.h" 10 #include "content/common/gpu/gpu_messages.h" 11 12 namespace content { 13 14 BrowserCompositorOutputSurfaceProxy::BrowserCompositorOutputSurfaceProxy( 15 IDMap<BrowserCompositorOutputSurface>* surface_map) 16 : surface_map_(surface_map), 17 connected_to_gpu_process_host_id_(0) {} 18 19 BrowserCompositorOutputSurfaceProxy::~BrowserCompositorOutputSurfaceProxy() {} 20 21 void BrowserCompositorOutputSurfaceProxy::ConnectToGpuProcessHost( 22 base::SingleThreadTaskRunner* compositor_thread_task_runner) { 23 BrowserGpuChannelHostFactory* factory = 24 BrowserGpuChannelHostFactory::instance(); 25 26 int gpu_process_host_id = factory->GpuProcessHostId(); 27 if (connected_to_gpu_process_host_id_ == gpu_process_host_id) 28 return; 29 30 const uint32 kMessagesToFilter[] = { GpuHostMsg_UpdateVSyncParameters::ID }; 31 factory->SetHandlerForControlMessages( 32 kMessagesToFilter, 33 arraysize(kMessagesToFilter), 34 base::Bind(&BrowserCompositorOutputSurfaceProxy:: 35 OnMessageReceivedOnCompositorThread, 36 this), 37 compositor_thread_task_runner); 38 connected_to_gpu_process_host_id_ = gpu_process_host_id; 39 } 40 41 void BrowserCompositorOutputSurfaceProxy::OnMessageReceivedOnCompositorThread( 42 const IPC::Message& message) { 43 IPC_BEGIN_MESSAGE_MAP(BrowserCompositorOutputSurfaceProxy, message) 44 IPC_MESSAGE_HANDLER(GpuHostMsg_UpdateVSyncParameters, 45 OnUpdateVSyncParametersOnCompositorThread); 46 IPC_END_MESSAGE_MAP() 47 } 48 49 void 50 BrowserCompositorOutputSurfaceProxy::OnUpdateVSyncParametersOnCompositorThread( 51 int surface_id, 52 base::TimeTicks timebase, 53 base::TimeDelta interval) { 54 BrowserCompositorOutputSurface* surface = surface_map_->Lookup(surface_id); 55 if (surface) 56 surface->OnUpdateVSyncParameters(timebase, interval); 57 } 58 } // namespace content 59