Revert 264226 "Reduce dependency of TiclInvalidationService on P..."
[chromium-blink-merge.git] / cc / test / fake_output_surface.cc
blob920b68940c7aea80b23534c60436050206a5b537
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 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 there is not BeginFrame emulation from the FrameRateController,
92 // then we just post a BeginFrame to emulate it as part of the test.
93 if (enable && !frame_rate_controller_) {
94 base::MessageLoop::current()->PostDelayedTask(
95 FROM_HERE,
96 base::Bind(&FakeOutputSurface::OnBeginFrame,
97 fake_weak_ptr_factory_.GetWeakPtr()),
98 base::TimeDelta::FromMilliseconds(16));
102 void FakeOutputSurface::OnBeginFrame() {
103 OutputSurface::BeginFrame(BeginFrameArgs::CreateForTesting());
107 bool FakeOutputSurface::ForcedDrawToSoftwareDevice() const {
108 return forced_draw_to_software_device_;
111 bool FakeOutputSurface::BindToClient(OutputSurfaceClient* client) {
112 if (OutputSurface::BindToClient(client)) {
113 client_ = client;
114 if (memory_policy_to_set_at_bind_) {
115 client_->SetMemoryPolicy(*memory_policy_to_set_at_bind_.get());
116 memory_policy_to_set_at_bind_.reset();
118 return true;
119 } else {
120 return false;
124 void FakeOutputSurface::SetTreeActivationCallback(
125 const base::Closure& callback) {
126 DCHECK(client_);
127 client_->SetTreeActivationCallback(callback);
130 void FakeOutputSurface::ReturnResource(unsigned id, CompositorFrameAck* ack) {
131 TransferableResourceArray::iterator it;
132 for (it = resources_held_by_parent_.begin();
133 it != resources_held_by_parent_.end();
134 ++it) {
135 if (it->id == id)
136 break;
138 DCHECK(it != resources_held_by_parent_.end());
139 ack->resources.push_back(it->ToReturnedResource());
140 resources_held_by_parent_.erase(it);
143 bool FakeOutputSurface::HasExternalStencilTest() const {
144 return has_external_stencil_test_;
147 void FakeOutputSurface::SetMemoryPolicyToSetAtBind(
148 scoped_ptr<ManagedMemoryPolicy> memory_policy_to_set_at_bind) {
149 memory_policy_to_set_at_bind_.swap(memory_policy_to_set_at_bind);
152 } // namespace cc