summaryrefslogtreecommitdiffstats
path: root/content/browser/aura/browser_compositor_output_surface_proxy.cc
blob: e86e5b8c69c458af32b60bef84c669851096d564 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "content/browser/aura/browser_compositor_output_surface_proxy.h"

#include "base/bind.h"
#include "content/browser/aura/browser_compositor_output_surface.h"
#include "content/browser/gpu/browser_gpu_channel_host_factory.h"
#include "content/common/gpu/gpu_messages.h"

namespace content {

BrowserCompositorOutputSurfaceProxy::BrowserCompositorOutputSurfaceProxy(
    IDMap<BrowserCompositorOutputSurface>* surface_map)
    : surface_map_(surface_map),
      connected_to_gpu_process_host_id_(0) {}

BrowserCompositorOutputSurfaceProxy::~BrowserCompositorOutputSurfaceProxy() {}

void BrowserCompositorOutputSurfaceProxy::ConnectToGpuProcessHost(
    base::SingleThreadTaskRunner* compositor_thread_task_runner) {
  BrowserGpuChannelHostFactory* factory =
      BrowserGpuChannelHostFactory::instance();

  int gpu_process_host_id = factory->GpuProcessHostId();
  if (connected_to_gpu_process_host_id_ == gpu_process_host_id)
    return;

  const uint32 kMessagesToFilter[] = { GpuHostMsg_UpdateVSyncParameters::ID };
  factory->SetHandlerForControlMessages(
      kMessagesToFilter,
      arraysize(kMessagesToFilter),
      base::Bind(&BrowserCompositorOutputSurfaceProxy::
                     OnMessageReceivedOnCompositorThread,
                 this),
      compositor_thread_task_runner);
  connected_to_gpu_process_host_id_ = gpu_process_host_id;
}

void BrowserCompositorOutputSurfaceProxy::OnMessageReceivedOnCompositorThread(
    const IPC::Message& message) {
  IPC_BEGIN_MESSAGE_MAP(BrowserCompositorOutputSurfaceProxy, message)
      IPC_MESSAGE_HANDLER(GpuHostMsg_UpdateVSyncParameters,
                          OnUpdateVSyncParametersOnCompositorThread);
  IPC_END_MESSAGE_MAP()
}

void
BrowserCompositorOutputSurfaceProxy::OnUpdateVSyncParametersOnCompositorThread(
    int surface_id,
    base::TimeTicks timebase,
    base::TimeDelta interval) {
  BrowserCompositorOutputSurface* surface = surface_map_->Lookup(surface_id);
  if (surface)
    surface->OnUpdateVSyncParameters(timebase, interval);
}
}  // namespace content