[Android] Expose more GoogleUtils to Java.
[chromium-blink-merge.git] / cc / test / fake_output_surface.cc
blob3346b562d97b6f9d1be8a240ecc073a4482e086e
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 bool delegated_rendering)
20 : OutputSurface(context_provider),
21 client_(NULL),
22 num_sent_frames_(0),
23 needs_begin_frame_(false),
24 forced_draw_to_software_device_(false),
25 has_external_stencil_test_(false),
26 fake_weak_ptr_factory_(this) {
27 if (delegated_rendering) {
28 capabilities_.delegated_rendering = true;
29 capabilities_.max_frames_pending = 1;
33 FakeOutputSurface::FakeOutputSurface(
34 scoped_ptr<SoftwareOutputDevice> software_device,
35 bool delegated_rendering)
36 : OutputSurface(software_device.Pass()),
37 client_(NULL),
38 num_sent_frames_(0),
39 forced_draw_to_software_device_(false),
40 has_external_stencil_test_(false),
41 fake_weak_ptr_factory_(this) {
42 if (delegated_rendering) {
43 capabilities_.delegated_rendering = true;
44 capabilities_.max_frames_pending = 1;
48 FakeOutputSurface::FakeOutputSurface(
49 scoped_refptr<ContextProvider> context_provider,
50 scoped_ptr<SoftwareOutputDevice> software_device,
51 bool delegated_rendering)
52 : OutputSurface(context_provider, software_device.Pass()),
53 client_(NULL),
54 num_sent_frames_(0),
55 forced_draw_to_software_device_(false),
56 has_external_stencil_test_(false),
57 fake_weak_ptr_factory_(this) {
58 if (delegated_rendering) {
59 capabilities_.delegated_rendering = true;
60 capabilities_.max_frames_pending = 1;
64 FakeOutputSurface::~FakeOutputSurface() {}
66 void FakeOutputSurface::SwapBuffers(CompositorFrame* frame) {
67 if (frame->software_frame_data || frame->delegated_frame_data ||
68 !context_provider()) {
69 frame->AssignTo(&last_sent_frame_);
71 if (last_sent_frame_.delegated_frame_data) {
72 resources_held_by_parent_.insert(
73 resources_held_by_parent_.end(),
74 last_sent_frame_.delegated_frame_data->resource_list.begin(),
75 last_sent_frame_.delegated_frame_data->resource_list.end());
78 ++num_sent_frames_;
79 PostSwapBuffersComplete();
80 client_->DidSwapBuffers();
81 } else {
82 OutputSurface::SwapBuffers(frame);
83 frame->AssignTo(&last_sent_frame_);
84 ++num_sent_frames_;
88 void FakeOutputSurface::SetNeedsBeginFrame(bool enable) {
89 needs_begin_frame_ = enable;
90 OutputSurface::SetNeedsBeginFrame(enable);
92 if (enable) {
93 base::MessageLoop::current()->PostDelayedTask(
94 FROM_HERE,
95 base::Bind(&FakeOutputSurface::OnBeginFrame,
96 fake_weak_ptr_factory_.GetWeakPtr()),
97 base::TimeDelta::FromMilliseconds(16));
101 void FakeOutputSurface::OnBeginFrame() {
102 client_->BeginFrame(CreateBeginFrameArgsForTesting());
106 bool FakeOutputSurface::ForcedDrawToSoftwareDevice() const {
107 return forced_draw_to_software_device_;
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_.reset();
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 void FakeOutputSurface::SetMemoryPolicyToSetAtBind(
147 scoped_ptr<ManagedMemoryPolicy> memory_policy_to_set_at_bind) {
148 memory_policy_to_set_at_bind_.swap(memory_policy_to_set_at_bind);
151 } // namespace cc