OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #include "cc/test/fake_output_surface.h" |
| 6 |
| 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" |
| 14 |
| 15 namespace cc { |
| 16 |
| 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; |
| 29 } |
| 30 } |
| 31 |
| 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; |
| 43 } |
| 44 } |
| 45 |
| 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; |
| 57 } |
| 58 } |
| 59 |
| 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; |
| 72 } |
| 73 } |
| 74 |
| 75 FakeOutputSurface::~FakeOutputSurface() {} |
| 76 |
| 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_); |
| 81 |
| 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()); |
| 87 } |
| 88 |
| 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_; |
| 94 } |
| 95 PostSwapBuffersComplete(); |
| 96 client_->DidSwapBuffers(); |
| 97 } |
| 98 |
| 99 void FakeOutputSurface::BindFramebuffer() { |
| 100 if (framebuffer_) |
| 101 context_provider_->ContextGL()->BindFramebuffer(GL_FRAMEBUFFER, |
| 102 framebuffer_); |
| 103 else |
| 104 OutputSurface::BindFramebuffer(); |
| 105 } |
| 106 |
| 107 bool FakeOutputSurface::BindToClient(OutputSurfaceClient* client) { |
| 108 if (OutputSurface::BindToClient(client)) { |
| 109 client_ = client; |
| 110 return true; |
| 111 } else { |
| 112 return false; |
| 113 } |
| 114 } |
| 115 |
| 116 void FakeOutputSurface::SetTreeActivationCallback( |
| 117 const base::Closure& callback) { |
| 118 DCHECK(client_); |
| 119 client_->SetTreeActivationCallback(callback); |
| 120 } |
| 121 |
| 122 void FakeOutputSurface::ReturnResource(unsigned id, CompositorFrameAck* ack) { |
| 123 TransferableResourceArray::iterator it; |
| 124 for (it = resources_held_by_parent_.begin(); |
| 125 it != resources_held_by_parent_.end(); |
| 126 ++it) { |
| 127 if (it->id == id) |
| 128 break; |
| 129 } |
| 130 DCHECK(it != resources_held_by_parent_.end()); |
| 131 ack->resources.push_back(it->ToReturnedResource()); |
| 132 resources_held_by_parent_.erase(it); |
| 133 } |
| 134 |
| 135 bool FakeOutputSurface::HasExternalStencilTest() const { |
| 136 return has_external_stencil_test_; |
| 137 } |
| 138 |
| 139 } // namespace cc |
OLD | NEW |