cc: Added inline to Tile::IsReadyToDraw
[chromium-blink-merge.git] / cc / test / fake_output_surface.cc
blobbc94f1942a11f5eb946dcdd35eb0a9c49cb53888
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 fake_weak_ptr_factory_(this) {
25 if (delegated_rendering) {
26 capabilities_.delegated_rendering = true;
27 capabilities_.max_frames_pending = 1;
31 FakeOutputSurface::FakeOutputSurface(
32 scoped_ptr<SoftwareOutputDevice> software_device, bool delegated_rendering)
33 : OutputSurface(software_device.Pass()),
34 client_(NULL),
35 num_sent_frames_(0),
36 forced_draw_to_software_device_(false),
37 fake_weak_ptr_factory_(this) {
38 if (delegated_rendering) {
39 capabilities_.delegated_rendering = true;
40 capabilities_.max_frames_pending = 1;
44 FakeOutputSurface::FakeOutputSurface(
45 scoped_refptr<ContextProvider> context_provider,
46 scoped_ptr<SoftwareOutputDevice> software_device,
47 bool delegated_rendering)
48 : OutputSurface(context_provider, software_device.Pass()),
49 client_(NULL),
50 num_sent_frames_(0),
51 forced_draw_to_software_device_(false),
52 fake_weak_ptr_factory_(this) {
53 if (delegated_rendering) {
54 capabilities_.delegated_rendering = true;
55 capabilities_.max_frames_pending = 1;
59 FakeOutputSurface::~FakeOutputSurface() {}
61 void FakeOutputSurface::SwapBuffers(CompositorFrame* frame) {
62 if (frame->software_frame_data || frame->delegated_frame_data ||
63 !context_provider()) {
64 frame->AssignTo(&last_sent_frame_);
66 if (last_sent_frame_.delegated_frame_data) {
67 resources_held_by_parent_.insert(
68 resources_held_by_parent_.end(),
69 last_sent_frame_.delegated_frame_data->resource_list.begin(),
70 last_sent_frame_.delegated_frame_data->resource_list.end());
73 ++num_sent_frames_;
74 PostSwapBuffersComplete();
75 DidSwapBuffers();
76 } else {
77 OutputSurface::SwapBuffers(frame);
78 frame->AssignTo(&last_sent_frame_);
79 ++num_sent_frames_;
83 void FakeOutputSurface::SetNeedsBeginFrame(bool enable) {
84 needs_begin_frame_ = enable;
85 OutputSurface::SetNeedsBeginFrame(enable);
87 // If there is not BeginFrame emulation from the FrameRateController,
88 // then we just post a BeginFrame to emulate it as part of the test.
89 if (enable && !frame_rate_controller_) {
90 base::MessageLoop::current()->PostDelayedTask(
91 FROM_HERE, base::Bind(&FakeOutputSurface::OnBeginFrame,
92 fake_weak_ptr_factory_.GetWeakPtr()),
93 base::TimeDelta::FromMilliseconds(16));
97 void FakeOutputSurface::OnBeginFrame() {
98 OutputSurface::BeginFrame(BeginFrameArgs::CreateForTesting());
102 bool FakeOutputSurface::ForcedDrawToSoftwareDevice() const {
103 return forced_draw_to_software_device_;
106 bool FakeOutputSurface::BindToClient(OutputSurfaceClient* client) {
107 if (OutputSurface::BindToClient(client)) {
108 client_ = client;
109 return true;
110 } else {
111 return false;
115 void FakeOutputSurface::SetTreeActivationCallback(
116 const base::Closure& callback) {
117 DCHECK(client_);
118 client_->SetTreeActivationCallback(callback);
121 void FakeOutputSurface::ReturnResource(unsigned id, CompositorFrameAck* ack) {
122 TransferableResourceArray::iterator it;
123 for (it = resources_held_by_parent_.begin();
124 it != resources_held_by_parent_.end();
125 ++it) {
126 if (it->id == id)
127 break;
129 DCHECK(it != resources_held_by_parent_.end());
130 ack->resources.push_back(it->ToReturnedResource());
131 resources_held_by_parent_.erase(it);
134 } // namespace cc