summaryrefslogtreecommitdiffstats
path: root/cc/test/fake_output_surface.cc
blob: 6c5bc9f849d0fc95ec0b7c4637aeb04c4c35a036 (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
// Copyright 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 "cc/test/fake_output_surface.h"

#include "base/bind.h"
#include "base/message_loop.h"
#include "cc/output/compositor_frame_ack.h"
#include "cc/output/output_surface_client.h"

namespace cc {

FakeOutputSurface::FakeOutputSurface(
    scoped_ptr<WebKit::WebGraphicsContext3D> context3d, bool has_parent)
    : OutputSurface(context3d.Pass()),
      num_sent_frames_(0),
      needs_begin_frame_(false),
      forced_draw_to_software_device_(false),
      weak_ptr_factory_(this) {
  capabilities_.has_parent_compositor = has_parent;
}

FakeOutputSurface::FakeOutputSurface(
    scoped_ptr<SoftwareOutputDevice> software_device, bool has_parent)
    : OutputSurface(software_device.Pass()),
      num_sent_frames_(0),
      forced_draw_to_software_device_(false),
      weak_ptr_factory_(this) {
  capabilities_.has_parent_compositor = has_parent;
}

FakeOutputSurface::~FakeOutputSurface() {}

void FakeOutputSurface::SendFrameToParentCompositor(
    CompositorFrame* frame) {
  frame->AssignTo(&last_sent_frame_);
  ++num_sent_frames_;
  base::MessageLoop::current()->PostTask(
      FROM_HERE, base::Bind(&FakeOutputSurface::SendFrameAck,
                            weak_ptr_factory_.GetWeakPtr()));
}

void FakeOutputSurface::SetNeedsBeginFrame(bool enable) {
  needs_begin_frame_ = enable;
}

void FakeOutputSurface::BeginFrame(base::TimeTicks frame_time) {
  client_->BeginFrame(frame_time);
}

bool FakeOutputSurface::ForcedDrawToSoftwareDevice() const {
  return forced_draw_to_software_device_;
}

void FakeOutputSurface::SendFrameAck() {
  CompositorFrameAck ack;
  client_->OnSendFrameToParentCompositorAck(ack);
}

}  // namespace cc