summaryrefslogtreecommitdiffstats
path: root/content/renderer/gpu/compositor_output_surface.cc
blob: 65a6f4a5503b6fa0e8b0b7d12769b7250501c9b2 (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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// Copyright (c) 2012 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/renderer/gpu/compositor_output_surface.h"

#include "base/message_loop_proxy.h"
#include "cc/compositor_frame.h"
#include "cc/output_surface_client.h"
#include "content/common/view_messages.h"
#include "content/renderer/render_thread_impl.h"
#include "ipc/ipc_forwarding_message_filter.h"
#include "ipc/ipc_sync_channel.h"
#include "ipc/ipc_sync_message_filter.h"
#include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3D.h"

using cc::CompositorFrame;
using cc::SoftwareOutputDevice;
using WebKit::WebGraphicsContext3D;

namespace content {

//------------------------------------------------------------------------------

// static
IPC::ForwardingMessageFilter* CompositorOutputSurface::CreateFilter(
    base::TaskRunner* target_task_runner)
{
  uint32 messages_to_filter[] = {ViewMsg_UpdateVSyncParameters::ID};
  return new IPC::ForwardingMessageFilter(
      messages_to_filter, arraysize(messages_to_filter),
      target_task_runner);
}

CompositorOutputSurface::CompositorOutputSurface(
    int32 routing_id,
    WebGraphicsContext3D* context3D,
    cc::SoftwareOutputDevice* software_device)
    : output_surface_filter_(
          RenderThreadImpl::current()->compositor_output_surface_filter()),
      client_(NULL),
      routing_id_(routing_id),
      context3D_(context3D),
      software_device_(software_device) {
  DCHECK(output_surface_filter_);
  capabilities_.has_parent_compositor = false;
  DetachFromThread();
}

CompositorOutputSurface::~CompositorOutputSurface() {
  DCHECK(CalledOnValidThread());
  if (!client_)
    return;
  output_surface_proxy_->ClearOutputSurface();
  output_surface_filter_->RemoveRoute(routing_id_);
}

const struct cc::OutputSurface::Capabilities&
    CompositorOutputSurface::Capabilities() const {
  DCHECK(CalledOnValidThread());
  return capabilities_;
}

bool CompositorOutputSurface::BindToClient(
    cc::OutputSurfaceClient* client) {
  DCHECK(CalledOnValidThread());
  DCHECK(!client_);
  if (context3D_.get()) {
    if (!context3D_->makeContextCurrent())
      return false;
  }

  client_ = client;

  output_surface_proxy_ = new CompositorOutputSurfaceProxy(this);
  output_surface_filter_->AddRoute(
      routing_id_,
      base::Bind(&CompositorOutputSurfaceProxy::OnMessageReceived,
                 output_surface_proxy_));

  return true;
}

WebGraphicsContext3D* CompositorOutputSurface::Context3D() const {
  DCHECK(CalledOnValidThread());
  return context3D_.get();
}

cc::SoftwareOutputDevice* CompositorOutputSurface::SoftwareDevice() const {
  return software_device_.get();
}

void CompositorOutputSurface::SendFrameToParentCompositor(
    cc::CompositorFrame* frame) {
  DCHECK(CalledOnValidThread());
  Send(new ViewHostMsg_SwapCompositorFrame(routing_id_, *frame));
}

void CompositorOutputSurface::OnMessageReceived(const IPC::Message& message) {
  DCHECK(CalledOnValidThread());
  if (!client_)
    return;
  IPC_BEGIN_MESSAGE_MAP(CompositorOutputSurface, message)
    IPC_MESSAGE_HANDLER(ViewMsg_UpdateVSyncParameters, OnUpdateVSyncParameters);
  IPC_END_MESSAGE_MAP()
}

void CompositorOutputSurface::OnUpdateVSyncParameters(
    base::TimeTicks timebase, base::TimeDelta interval) {
  DCHECK(CalledOnValidThread());
  DCHECK(client_);
  client_->OnVSyncParametersChanged(timebase, interval);
}

bool CompositorOutputSurface::Send(IPC::Message* message) {
  return ChildThread::current()->sync_message_filter()->Send(message);
}

}  // namespace content