Delete chrome.mediaGalleriesPrivate because the functionality unique to it has since...
[chromium-blink-merge.git] / cc / test / fake_output_surface.cc
blob46efba09f92dd7344a4f900ce6cf4bb13e873ee7
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 has_external_stencil_test_(false) {
24 if (delegated_rendering) {
25 capabilities_.delegated_rendering = true;
26 capabilities_.max_frames_pending = 1;
30 FakeOutputSurface::FakeOutputSurface(
31 scoped_ptr<SoftwareOutputDevice> software_device,
32 bool delegated_rendering)
33 : OutputSurface(software_device.Pass()),
34 client_(NULL),
35 num_sent_frames_(0),
36 has_external_stencil_test_(false) {
37 if (delegated_rendering) {
38 capabilities_.delegated_rendering = true;
39 capabilities_.max_frames_pending = 1;
43 FakeOutputSurface::FakeOutputSurface(
44 scoped_refptr<ContextProvider> context_provider,
45 scoped_ptr<SoftwareOutputDevice> software_device,
46 bool delegated_rendering)
47 : OutputSurface(context_provider, software_device.Pass()),
48 client_(NULL),
49 num_sent_frames_(0),
50 has_external_stencil_test_(false) {
51 if (delegated_rendering) {
52 capabilities_.delegated_rendering = true;
53 capabilities_.max_frames_pending = 1;
57 FakeOutputSurface::~FakeOutputSurface() {}
59 void FakeOutputSurface::SwapBuffers(CompositorFrame* frame) {
60 if (frame->software_frame_data || frame->delegated_frame_data ||
61 !context_provider()) {
62 frame->AssignTo(&last_sent_frame_);
64 if (last_sent_frame_.delegated_frame_data) {
65 resources_held_by_parent_.insert(
66 resources_held_by_parent_.end(),
67 last_sent_frame_.delegated_frame_data->resource_list.begin(),
68 last_sent_frame_.delegated_frame_data->resource_list.end());
71 ++num_sent_frames_;
72 } else {
73 last_swap_rect_ = frame->gl_frame_data->sub_buffer_rect;
74 frame->AssignTo(&last_sent_frame_);
75 ++num_sent_frames_;
77 PostSwapBuffersComplete();
78 client_->DidSwapBuffers();
81 bool FakeOutputSurface::BindToClient(OutputSurfaceClient* client) {
82 if (OutputSurface::BindToClient(client)) {
83 client_ = client;
84 if (memory_policy_to_set_at_bind_) {
85 client_->SetMemoryPolicy(*memory_policy_to_set_at_bind_.get());
86 memory_policy_to_set_at_bind_ = nullptr;
88 return true;
89 } else {
90 return false;
94 void FakeOutputSurface::SetTreeActivationCallback(
95 const base::Closure& callback) {
96 DCHECK(client_);
97 client_->SetTreeActivationCallback(callback);
100 void FakeOutputSurface::ReturnResource(unsigned id, CompositorFrameAck* ack) {
101 TransferableResourceArray::iterator it;
102 for (it = resources_held_by_parent_.begin();
103 it != resources_held_by_parent_.end();
104 ++it) {
105 if (it->id == id)
106 break;
108 DCHECK(it != resources_held_by_parent_.end());
109 ack->resources.push_back(it->ToReturnedResource());
110 resources_held_by_parent_.erase(it);
113 bool FakeOutputSurface::HasExternalStencilTest() const {
114 return has_external_stencil_test_;
117 void FakeOutputSurface::SetMemoryPolicyToSetAtBind(
118 scoped_ptr<ManagedMemoryPolicy> memory_policy_to_set_at_bind) {
119 memory_policy_to_set_at_bind_.swap(memory_policy_to_set_at_bind);
122 } // namespace cc