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 | 11 |
12 namespace cc { | 12 namespace cc { |
13 | 13 |
14 FakeOutputSurface::FakeOutputSurface( | 14 FakeOutputSurface::FakeOutputSurface( |
15 scoped_ptr<WebKit::WebGraphicsContext3D> context3d, bool has_parent) | 15 scoped_ptr<WebKit::WebGraphicsContext3D> context3d, |
| 16 bool delegated_rendering) |
16 : OutputSurface(context3d.Pass()), | 17 : OutputSurface(context3d.Pass()), |
17 num_sent_frames_(0), | 18 num_sent_frames_(0), |
18 needs_begin_frame_(false), | 19 needs_begin_frame_(false), |
19 forced_draw_to_software_device_(false), | 20 forced_draw_to_software_device_(false), |
20 weak_ptr_factory_(this) { | 21 weak_ptr_factory_(this) { |
21 capabilities_.has_parent_compositor = has_parent; | 22 if (delegated_rendering) { |
| 23 capabilities_.delegated_rendering = true; |
| 24 capabilities_.max_frames_pending = 1; |
| 25 } |
22 } | 26 } |
23 | 27 |
24 FakeOutputSurface::FakeOutputSurface( | 28 FakeOutputSurface::FakeOutputSurface( |
25 scoped_ptr<SoftwareOutputDevice> software_device, bool has_parent) | 29 scoped_ptr<SoftwareOutputDevice> software_device, bool delegated_rendering) |
26 : OutputSurface(software_device.Pass()), | 30 : OutputSurface(software_device.Pass()), |
27 num_sent_frames_(0), | 31 num_sent_frames_(0), |
28 forced_draw_to_software_device_(false), | 32 forced_draw_to_software_device_(false), |
29 weak_ptr_factory_(this) { | 33 weak_ptr_factory_(this) { |
30 capabilities_.has_parent_compositor = has_parent; | 34 if (delegated_rendering) { |
| 35 capabilities_.delegated_rendering = true; |
| 36 capabilities_.max_frames_pending = 1; |
| 37 } |
31 } | 38 } |
32 | 39 |
33 FakeOutputSurface::FakeOutputSurface( | 40 FakeOutputSurface::FakeOutputSurface( |
34 scoped_ptr<WebKit::WebGraphicsContext3D> context3d, | 41 scoped_ptr<WebKit::WebGraphicsContext3D> context3d, |
35 scoped_ptr<SoftwareOutputDevice> software_device, | 42 scoped_ptr<SoftwareOutputDevice> software_device, |
36 bool has_parent) | 43 bool delegated_rendering) |
37 : OutputSurface(context3d.Pass(), software_device.Pass()), | 44 : OutputSurface(context3d.Pass(), software_device.Pass()), |
38 num_sent_frames_(0), | 45 num_sent_frames_(0), |
39 forced_draw_to_software_device_(false), | 46 forced_draw_to_software_device_(false), |
40 weak_ptr_factory_(this) { | 47 weak_ptr_factory_(this) { |
41 capabilities_.has_parent_compositor = has_parent; | 48 if (delegated_rendering) { |
| 49 capabilities_.delegated_rendering = true; |
| 50 capabilities_.max_frames_pending = 1; |
| 51 } |
42 } | 52 } |
43 | 53 |
44 FakeOutputSurface::~FakeOutputSurface() {} | 54 FakeOutputSurface::~FakeOutputSurface() {} |
45 | 55 |
46 void FakeOutputSurface::SendFrameToParentCompositor( | 56 void FakeOutputSurface::SwapBuffers(CompositorFrame* frame) { |
47 CompositorFrame* frame) { | 57 if (frame->software_frame_data || frame->delegated_frame_data || |
48 frame->AssignTo(&last_sent_frame_); | 58 !context3d()) { |
49 ++num_sent_frames_; | 59 frame->AssignTo(&last_sent_frame_); |
50 base::MessageLoop::current()->PostTask( | 60 ++num_sent_frames_; |
51 FROM_HERE, base::Bind(&FakeOutputSurface::SendFrameAck, | 61 base::MessageLoop::current()->PostTask( |
52 weak_ptr_factory_.GetWeakPtr())); | 62 FROM_HERE, |
| 63 base::Bind(&FakeOutputSurface::SendFrameAck, |
| 64 weak_ptr_factory_.GetWeakPtr())); |
| 65 } else { |
| 66 OutputSurface::SwapBuffers(frame); |
| 67 frame->AssignTo(&last_sent_frame_); |
| 68 ++num_sent_frames_; |
| 69 } |
| 70 } |
| 71 |
| 72 void FakeOutputSurface::SendFrameAck() { |
| 73 CompositorFrameAck ack; |
| 74 client_->OnSwapBuffersComplete(&ack); |
53 } | 75 } |
54 | 76 |
55 void FakeOutputSurface::SetNeedsBeginFrame(bool enable) { | 77 void FakeOutputSurface::SetNeedsBeginFrame(bool enable) { |
56 needs_begin_frame_ = enable; | 78 needs_begin_frame_ = enable; |
57 } | 79 } |
58 | 80 |
59 void FakeOutputSurface::BeginFrame(base::TimeTicks frame_time) { | 81 void FakeOutputSurface::BeginFrame(base::TimeTicks frame_time) { |
60 client_->BeginFrame(frame_time); | 82 client_->BeginFrame(frame_time); |
61 } | 83 } |
62 | 84 |
63 bool FakeOutputSurface::ForcedDrawToSoftwareDevice() const { | 85 bool FakeOutputSurface::ForcedDrawToSoftwareDevice() const { |
64 return forced_draw_to_software_device_; | 86 return forced_draw_to_software_device_; |
65 } | 87 } |
66 | 88 |
67 void FakeOutputSurface::SendFrameAck() { | |
68 CompositorFrameAck ack; | |
69 client_->OnSendFrameToParentCompositorAck(ack); | |
70 } | |
71 | |
72 } // namespace cc | 89 } // namespace cc |
OLD | NEW |