Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / cc / test / fake_output_surface.cc
blob352b6e49945770260571e986514247715a00cc24
1 // Copyright 2012 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.
5 #include "cc/test/fake_output_surface.h"
7 #include "base/bind.h"
8 #include "base/message_loop/message_loop.h"
9 #include "cc/output/compositor_frame_ack.h"
10 #include "cc/output/output_surface_client.h"
11 #include "cc/resources/returned_resource.h"
12 #include "testing/gtest/include/gtest/gtest.h"
14 namespace cc {
16 FakeOutputSurface::FakeOutputSurface(
17 scoped_refptr<ContextProvider> context_provider,
18 bool delegated_rendering)
19 : OutputSurface(context_provider),
20 client_(NULL),
21 num_sent_frames_(0),
22 needs_begin_frame_(false),
23 forced_draw_to_software_device_(false),
24 has_external_stencil_test_(false),
25 fake_weak_ptr_factory_(this) {
26 if (delegated_rendering) {
27 capabilities_.delegated_rendering = true;
28 capabilities_.max_frames_pending = 1;
32 FakeOutputSurface::FakeOutputSurface(
33 scoped_ptr<SoftwareOutputDevice> software_device,
34 bool delegated_rendering)
35 : OutputSurface(software_device.Pass()),
36 client_(NULL),
37 num_sent_frames_(0),
38 forced_draw_to_software_device_(false),
39 has_external_stencil_test_(false),
40 fake_weak_ptr_factory_(this) {
41 if (delegated_rendering) {
42 capabilities_.delegated_rendering = true;
43 capabilities_.max_frames_pending = 1;
47 FakeOutputSurface::FakeOutputSurface(
48 scoped_refptr<ContextProvider> context_provider,
49 scoped_ptr<SoftwareOutputDevice> software_device,
50 bool delegated_rendering)
51 : OutputSurface(context_provider, software_device.Pass()),
52 client_(NULL),
53 num_sent_frames_(0),
54 forced_draw_to_software_device_(false),
55 has_external_stencil_test_(false),
56 fake_weak_ptr_factory_(this) {
57 if (delegated_rendering) {
58 capabilities_.delegated_rendering = true;
59 capabilities_.max_frames_pending = 1;
63 FakeOutputSurface::~FakeOutputSurface() {}
65 void FakeOutputSurface::SwapBuffers(CompositorFrame* frame) {
66 if (frame->software_frame_data || frame->delegated_frame_data ||
67 !context_provider()) {
68 frame->AssignTo(&last_sent_frame_);
70 if (last_sent_frame_.delegated_frame_data) {
71 resources_held_by_parent_.insert(
72 resources_held_by_parent_.end(),
73 last_sent_frame_.delegated_frame_data->resource_list.begin(),
74 last_sent_frame_.delegated_frame_data->resource_list.end());
77 ++num_sent_frames_;
78 PostSwapBuffersComplete();
79 client_->DidSwapBuffers();
80 } else {
81 OutputSurface::SwapBuffers(frame);
82 frame->AssignTo(&last_sent_frame_);
83 ++num_sent_frames_;
87 void FakeOutputSurface::SetNeedsBeginFrame(bool enable) {
88 needs_begin_frame_ = enable;
89 OutputSurface::SetNeedsBeginFrame(enable);
91 if (enable) {
92 base::MessageLoop::current()->PostDelayedTask(
93 FROM_HERE,
94 base::Bind(&FakeOutputSurface::OnBeginFrame,
95 fake_weak_ptr_factory_.GetWeakPtr()),
96 base::TimeDelta::FromMilliseconds(16));
100 void FakeOutputSurface::OnBeginFrame() {
101 client_->BeginFrame(BeginFrameArgs::CreateForTesting());
105 bool FakeOutputSurface::ForcedDrawToSoftwareDevice() const {
106 return forced_draw_to_software_device_;
109 bool FakeOutputSurface::BindToClient(OutputSurfaceClient* client) {
110 if (OutputSurface::BindToClient(client)) {
111 client_ = client;
112 if (memory_policy_to_set_at_bind_) {
113 client_->SetMemoryPolicy(*memory_policy_to_set_at_bind_.get());
114 memory_policy_to_set_at_bind_.reset();
116 return true;
117 } else {
118 return false;
122 void FakeOutputSurface::SetTreeActivationCallback(
123 const base::Closure& callback) {
124 DCHECK(client_);
125 client_->SetTreeActivationCallback(callback);
128 void FakeOutputSurface::ReturnResource(unsigned id, CompositorFrameAck* ack) {
129 TransferableResourceArray::iterator it;
130 for (it = resources_held_by_parent_.begin();
131 it != resources_held_by_parent_.end();
132 ++it) {
133 if (it->id == id)
134 break;
136 DCHECK(it != resources_held_by_parent_.end());
137 ack->resources.push_back(it->ToReturnedResource());
138 resources_held_by_parent_.erase(it);
141 bool FakeOutputSurface::HasExternalStencilTest() const {
142 return has_external_stencil_test_;
145 void FakeOutputSurface::SetMemoryPolicyToSetAtBind(
146 scoped_ptr<ManagedMemoryPolicy> memory_policy_to_set_at_bind) {
147 memory_policy_to_set_at_bind_.swap(memory_policy_to_set_at_bind);
150 } // namespace cc