Revert "Reland c91b178b07b0d - Delete dead signin code (SigninGlobalError)"
[chromium-blink-merge.git] / cc / test / fake_output_surface.cc
blob4ba49716889ef6e50e1575f535e905bd8d9755d7
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 "cc/test/begin_frame_args_test.h"
13 #include "testing/gtest/include/gtest/gtest.h"
15 namespace cc {
17 FakeOutputSurface::FakeOutputSurface(
18 scoped_refptr<ContextProvider> context_provider,
19 scoped_refptr<ContextProvider> worker_context_provider,
20 bool delegated_rendering)
21 : OutputSurface(context_provider, worker_context_provider),
22 client_(NULL),
23 num_sent_frames_(0),
24 has_external_stencil_test_(false),
25 suspended_for_recycle_(false),
26 framebuffer_(0) {
27 if (delegated_rendering) {
28 capabilities_.delegated_rendering = true;
29 capabilities_.max_frames_pending = 1;
33 FakeOutputSurface::FakeOutputSurface(
34 scoped_refptr<ContextProvider> context_provider,
35 bool delegated_rendering)
36 : OutputSurface(context_provider),
37 client_(NULL),
38 num_sent_frames_(0),
39 has_external_stencil_test_(false),
40 suspended_for_recycle_(false),
41 framebuffer_(0) {
42 if (delegated_rendering) {
43 capabilities_.delegated_rendering = true;
44 capabilities_.max_frames_pending = 1;
48 FakeOutputSurface::FakeOutputSurface(
49 scoped_ptr<SoftwareOutputDevice> software_device,
50 bool delegated_rendering)
51 : OutputSurface(software_device.Pass()),
52 client_(NULL),
53 num_sent_frames_(0),
54 has_external_stencil_test_(false),
55 suspended_for_recycle_(false),
56 framebuffer_(0) {
57 if (delegated_rendering) {
58 capabilities_.delegated_rendering = true;
59 capabilities_.max_frames_pending = 1;
63 FakeOutputSurface::FakeOutputSurface(
64 scoped_refptr<ContextProvider> context_provider,
65 scoped_ptr<SoftwareOutputDevice> software_device,
66 bool delegated_rendering)
67 : OutputSurface(context_provider, software_device.Pass()),
68 client_(NULL),
69 num_sent_frames_(0),
70 has_external_stencil_test_(false),
71 suspended_for_recycle_(false),
72 framebuffer_(0) {
73 if (delegated_rendering) {
74 capabilities_.delegated_rendering = true;
75 capabilities_.max_frames_pending = 1;
79 FakeOutputSurface::~FakeOutputSurface() {}
81 void FakeOutputSurface::SwapBuffers(CompositorFrame* frame) {
82 if (frame->delegated_frame_data || !context_provider()) {
83 frame->AssignTo(&last_sent_frame_);
85 if (last_sent_frame_.delegated_frame_data) {
86 resources_held_by_parent_.insert(
87 resources_held_by_parent_.end(),
88 last_sent_frame_.delegated_frame_data->resource_list.begin(),
89 last_sent_frame_.delegated_frame_data->resource_list.end());
92 ++num_sent_frames_;
93 } else {
94 last_swap_rect_ = frame->gl_frame_data->sub_buffer_rect;
95 frame->AssignTo(&last_sent_frame_);
96 ++num_sent_frames_;
98 PostSwapBuffersComplete();
99 client_->DidSwapBuffers();
102 void FakeOutputSurface::BindFramebuffer() {
103 if (framebuffer_)
104 context_provider_->ContextGL()->BindFramebuffer(GL_FRAMEBUFFER,
105 framebuffer_);
106 else
107 OutputSurface::BindFramebuffer();
110 bool FakeOutputSurface::BindToClient(OutputSurfaceClient* client) {
111 if (OutputSurface::BindToClient(client)) {
112 client_ = client;
113 if (memory_policy_to_set_at_bind_) {
114 client_->SetMemoryPolicy(*memory_policy_to_set_at_bind_.get());
115 memory_policy_to_set_at_bind_ = nullptr;
117 return true;
118 } else {
119 return false;
123 void FakeOutputSurface::SetTreeActivationCallback(
124 const base::Closure& callback) {
125 DCHECK(client_);
126 client_->SetTreeActivationCallback(callback);
129 void FakeOutputSurface::ReturnResource(unsigned id, CompositorFrameAck* ack) {
130 TransferableResourceArray::iterator it;
131 for (it = resources_held_by_parent_.begin();
132 it != resources_held_by_parent_.end();
133 ++it) {
134 if (it->id == id)
135 break;
137 DCHECK(it != resources_held_by_parent_.end());
138 ack->resources.push_back(it->ToReturnedResource());
139 resources_held_by_parent_.erase(it);
142 bool FakeOutputSurface::HasExternalStencilTest() const {
143 return has_external_stencil_test_;
146 bool FakeOutputSurface::SurfaceIsSuspendForRecycle() const {
147 return suspended_for_recycle_;
150 void FakeOutputSurface::SetMemoryPolicyToSetAtBind(
151 scoped_ptr<ManagedMemoryPolicy> memory_policy_to_set_at_bind) {
152 memory_policy_to_set_at_bind_.swap(memory_policy_to_set_at_bind);
155 } // namespace cc