| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "cc/test/fake_output_surface.h" | 5 #include "cc/test/fake_output_surface.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "cc/output/compositor_frame_ack.h" | 9 #include "cc/output/compositor_frame_ack.h" |
| 10 #include "cc/output/output_surface_client.h" | 10 #include "cc/output/output_surface_client.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" |
| 11 | 12 |
| 12 namespace cc { | 13 namespace cc { |
| 13 | 14 |
| 14 FakeOutputSurface::FakeOutputSurface( | 15 FakeOutputSurface::FakeOutputSurface( |
| 15 scoped_ptr<WebKit::WebGraphicsContext3D> context3d, | 16 scoped_ptr<WebKit::WebGraphicsContext3D> context3d, |
| 16 bool delegated_rendering) | 17 bool delegated_rendering) |
| 17 : OutputSurface(context3d.Pass()), | 18 : OutputSurface(context3d.Pass()), |
| 18 num_sent_frames_(0), | 19 num_sent_frames_(0), |
| 19 needs_begin_frame_(false), | 20 needs_begin_frame_(false), |
| 20 forced_draw_to_software_device_(false) { | 21 forced_draw_to_software_device_(false), |
| 22 fake_weak_ptr_factory_(this) { |
| 21 if (delegated_rendering) { | 23 if (delegated_rendering) { |
| 22 capabilities_.delegated_rendering = true; | 24 capabilities_.delegated_rendering = true; |
| 23 capabilities_.max_frames_pending = 1; | 25 capabilities_.max_frames_pending = 1; |
| 24 } | 26 } |
| 25 } | 27 } |
| 26 | 28 |
| 27 FakeOutputSurface::FakeOutputSurface( | 29 FakeOutputSurface::FakeOutputSurface( |
| 28 scoped_ptr<SoftwareOutputDevice> software_device, bool delegated_rendering) | 30 scoped_ptr<SoftwareOutputDevice> software_device, bool delegated_rendering) |
| 29 : OutputSurface(software_device.Pass()), | 31 : OutputSurface(software_device.Pass()), |
| 30 num_sent_frames_(0), | 32 num_sent_frames_(0), |
| 31 forced_draw_to_software_device_(false) { | 33 forced_draw_to_software_device_(false), |
| 34 fake_weak_ptr_factory_(this) { |
| 32 if (delegated_rendering) { | 35 if (delegated_rendering) { |
| 33 capabilities_.delegated_rendering = true; | 36 capabilities_.delegated_rendering = true; |
| 34 capabilities_.max_frames_pending = 1; | 37 capabilities_.max_frames_pending = 1; |
| 35 } | 38 } |
| 36 } | 39 } |
| 37 | 40 |
| 38 FakeOutputSurface::FakeOutputSurface( | 41 FakeOutputSurface::FakeOutputSurface( |
| 39 scoped_ptr<WebKit::WebGraphicsContext3D> context3d, | 42 scoped_ptr<WebKit::WebGraphicsContext3D> context3d, |
| 40 scoped_ptr<SoftwareOutputDevice> software_device, | 43 scoped_ptr<SoftwareOutputDevice> software_device, |
| 41 bool delegated_rendering) | 44 bool delegated_rendering) |
| 42 : OutputSurface(context3d.Pass(), software_device.Pass()), | 45 : OutputSurface(context3d.Pass(), software_device.Pass()), |
| 43 num_sent_frames_(0), | 46 num_sent_frames_(0), |
| 44 forced_draw_to_software_device_(false) { | 47 forced_draw_to_software_device_(false), |
| 48 fake_weak_ptr_factory_(this) { |
| 45 if (delegated_rendering) { | 49 if (delegated_rendering) { |
| 46 capabilities_.delegated_rendering = true; | 50 capabilities_.delegated_rendering = true; |
| 47 capabilities_.max_frames_pending = 1; | 51 capabilities_.max_frames_pending = 1; |
| 48 } | 52 } |
| 49 } | 53 } |
| 50 | 54 |
| 51 FakeOutputSurface::~FakeOutputSurface() {} | 55 FakeOutputSurface::~FakeOutputSurface() {} |
| 52 | 56 |
| 53 void FakeOutputSurface::SwapBuffers(CompositorFrame* frame) { | 57 void FakeOutputSurface::SwapBuffers(CompositorFrame* frame) { |
| 54 if (frame->software_frame_data || frame->delegated_frame_data || | 58 if (frame->software_frame_data || frame->delegated_frame_data || |
| 55 !context3d()) { | 59 !context3d()) { |
| 56 frame->AssignTo(&last_sent_frame_); | 60 frame->AssignTo(&last_sent_frame_); |
| 57 ++num_sent_frames_; | 61 ++num_sent_frames_; |
| 58 PostSwapBuffersComplete(); | 62 PostSwapBuffersComplete(); |
| 63 DidSwapBuffers(); |
| 59 } else { | 64 } else { |
| 60 OutputSurface::SwapBuffers(frame); | 65 OutputSurface::SwapBuffers(frame); |
| 61 frame->AssignTo(&last_sent_frame_); | 66 frame->AssignTo(&last_sent_frame_); |
| 62 ++num_sent_frames_; | 67 ++num_sent_frames_; |
| 63 } | 68 } |
| 64 } | 69 } |
| 65 | 70 |
| 66 void FakeOutputSurface::SetNeedsBeginFrame(bool enable) { | 71 void FakeOutputSurface::SetNeedsBeginFrame(bool enable) { |
| 67 needs_begin_frame_ = enable; | 72 needs_begin_frame_ = enable; |
| 73 OutputSurface::SetNeedsBeginFrame(enable); |
| 74 |
| 75 // If there is not BeginFrame emulation from the FrameRateController, |
| 76 // then we just post a BeginFrame to emulate it as part of the test. |
| 77 if (enable && !frame_rate_controller_) { |
| 78 base::MessageLoop::current()->PostDelayedTask( |
| 79 FROM_HERE, base::Bind(&FakeOutputSurface::OnBeginFrame, |
| 80 fake_weak_ptr_factory_.GetWeakPtr()), |
| 81 base::TimeDelta::FromMilliseconds(16)); |
| 82 } |
| 68 } | 83 } |
| 69 | 84 |
| 70 void FakeOutputSurface::BeginFrame(base::TimeTicks frame_time) { | 85 void FakeOutputSurface::OnBeginFrame() { |
| 71 client_->BeginFrame(frame_time); | 86 OutputSurface::BeginFrame(base::TimeTicks::Now()); |
| 72 } | 87 } |
| 73 | 88 |
| 89 |
| 74 bool FakeOutputSurface::ForcedDrawToSoftwareDevice() const { | 90 bool FakeOutputSurface::ForcedDrawToSoftwareDevice() const { |
| 75 return forced_draw_to_software_device_; | 91 return forced_draw_to_software_device_; |
| 76 } | 92 } |
| 77 | 93 |
| 78 } // namespace cc | 94 } // namespace cc |
| OLD | NEW |