Update check in KillingRendererClearsDescendantProxies test.
[chromium-blink-merge.git] / cc / test / fake_output_surface.cc
blob0279421669c27a8f38128662935896919f35754f
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 framebuffer_(0) {
26 if (delegated_rendering) {
27 capabilities_.delegated_rendering = true;
28 capabilities_.max_frames_pending = 1;
32 FakeOutputSurface::FakeOutputSurface(
33 scoped_refptr<ContextProvider> context_provider,
34 bool delegated_rendering)
35 : OutputSurface(context_provider),
36 client_(NULL),
37 num_sent_frames_(0),
38 has_external_stencil_test_(false),
39 framebuffer_(0) {
40 if (delegated_rendering) {
41 capabilities_.delegated_rendering = true;
42 capabilities_.max_frames_pending = 1;
46 FakeOutputSurface::FakeOutputSurface(
47 scoped_ptr<SoftwareOutputDevice> software_device,
48 bool delegated_rendering)
49 : OutputSurface(software_device.Pass()),
50 client_(NULL),
51 num_sent_frames_(0),
52 has_external_stencil_test_(false),
53 framebuffer_(0) {
54 if (delegated_rendering) {
55 capabilities_.delegated_rendering = true;
56 capabilities_.max_frames_pending = 1;
60 FakeOutputSurface::FakeOutputSurface(
61 scoped_refptr<ContextProvider> context_provider,
62 scoped_ptr<SoftwareOutputDevice> software_device,
63 bool delegated_rendering)
64 : OutputSurface(context_provider, software_device.Pass()),
65 client_(NULL),
66 num_sent_frames_(0),
67 has_external_stencil_test_(false),
68 framebuffer_(0) {
69 if (delegated_rendering) {
70 capabilities_.delegated_rendering = true;
71 capabilities_.max_frames_pending = 1;
75 FakeOutputSurface::~FakeOutputSurface() {}
77 void FakeOutputSurface::SwapBuffers(CompositorFrame* frame) {
78 if (frame->software_frame_data || frame->delegated_frame_data ||
79 !context_provider()) {
80 frame->AssignTo(&last_sent_frame_);
82 if (last_sent_frame_.delegated_frame_data) {
83 resources_held_by_parent_.insert(
84 resources_held_by_parent_.end(),
85 last_sent_frame_.delegated_frame_data->resource_list.begin(),
86 last_sent_frame_.delegated_frame_data->resource_list.end());
89 ++num_sent_frames_;
90 } else {
91 last_swap_rect_ = frame->gl_frame_data->sub_buffer_rect;
92 frame->AssignTo(&last_sent_frame_);
93 ++num_sent_frames_;
95 PostSwapBuffersComplete();
96 client_->DidSwapBuffers();
99 void FakeOutputSurface::BindFramebuffer() {
100 if (framebuffer_)
101 context_provider_->ContextGL()->BindFramebuffer(GL_FRAMEBUFFER,
102 framebuffer_);
103 else
104 OutputSurface::BindFramebuffer();
107 bool FakeOutputSurface::BindToClient(OutputSurfaceClient* client) {
108 if (OutputSurface::BindToClient(client)) {
109 client_ = client;
110 if (memory_policy_to_set_at_bind_) {
111 client_->SetMemoryPolicy(*memory_policy_to_set_at_bind_.get());
112 memory_policy_to_set_at_bind_ = nullptr;
114 return true;
115 } else {
116 return false;
120 void FakeOutputSurface::SetTreeActivationCallback(
121 const base::Closure& callback) {
122 DCHECK(client_);
123 client_->SetTreeActivationCallback(callback);
126 void FakeOutputSurface::ReturnResource(unsigned id, CompositorFrameAck* ack) {
127 TransferableResourceArray::iterator it;
128 for (it = resources_held_by_parent_.begin();
129 it != resources_held_by_parent_.end();
130 ++it) {
131 if (it->id == id)
132 break;
134 DCHECK(it != resources_held_by_parent_.end());
135 ack->resources.push_back(it->ToReturnedResource());
136 resources_held_by_parent_.erase(it);
139 bool FakeOutputSurface::HasExternalStencilTest() const {
140 return has_external_stencil_test_;
143 void FakeOutputSurface::SetMemoryPolicyToSetAtBind(
144 scoped_ptr<ManagedMemoryPolicy> memory_policy_to_set_at_bind) {
145 memory_policy_to_set_at_bind_.swap(memory_policy_to_set_at_bind);
148 } // namespace cc