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"
8 #include "base/message_loop.h"
9 #include "cc/output/compositor_frame_ack.h"
10 #include "cc/output/output_surface_client.h"
11 #include "testing/gtest/include/gtest/gtest.h"
15 FakeOutputSurface::FakeOutputSurface(
16 scoped_ptr
<WebKit::WebGraphicsContext3D
> context3d
,
17 bool delegated_rendering
)
18 : OutputSurface(context3d
.Pass()),
20 needs_begin_frame_(false),
21 forced_draw_to_software_device_(false),
22 fake_weak_ptr_factory_(this) {
23 if (delegated_rendering
) {
24 capabilities_
.delegated_rendering
= true;
25 capabilities_
.max_frames_pending
= 1;
29 FakeOutputSurface::FakeOutputSurface(
30 scoped_ptr
<SoftwareOutputDevice
> software_device
, bool delegated_rendering
)
31 : OutputSurface(software_device
.Pass()),
33 forced_draw_to_software_device_(false),
34 fake_weak_ptr_factory_(this) {
35 if (delegated_rendering
) {
36 capabilities_
.delegated_rendering
= true;
37 capabilities_
.max_frames_pending
= 1;
41 FakeOutputSurface::FakeOutputSurface(
42 scoped_ptr
<WebKit::WebGraphicsContext3D
> context3d
,
43 scoped_ptr
<SoftwareOutputDevice
> software_device
,
44 bool delegated_rendering
)
45 : OutputSurface(context3d
.Pass(), software_device
.Pass()),
47 forced_draw_to_software_device_(false),
48 fake_weak_ptr_factory_(this) {
49 if (delegated_rendering
) {
50 capabilities_
.delegated_rendering
= true;
51 capabilities_
.max_frames_pending
= 1;
55 FakeOutputSurface::~FakeOutputSurface() {}
57 void FakeOutputSurface::SwapBuffers(CompositorFrame
* frame
) {
58 if (frame
->software_frame_data
|| frame
->delegated_frame_data
||
60 frame
->AssignTo(&last_sent_frame_
);
62 PostSwapBuffersComplete();
65 OutputSurface::SwapBuffers(frame
);
66 frame
->AssignTo(&last_sent_frame_
);
71 void FakeOutputSurface::SetNeedsBeginFrame(bool enable
) {
72 needs_begin_frame_
= enable
;
73 OutputSurface::SetNeedsBeginFrame(enable
);
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));
85 void FakeOutputSurface::OnBeginFrame() {
86 OutputSurface::BeginFrame(BeginFrameArgs::CreateForTesting());
90 bool FakeOutputSurface::ForcedDrawToSoftwareDevice() const {
91 return forced_draw_to_software_device_
;
94 bool FakeOutputSurface::SetAndInitializeContext3D(
95 scoped_ptr
<WebKit::WebGraphicsContext3D
> context3d
) {
96 return InitializeAndSetContext3D(context3d
.Pass(),
97 scoped_refptr
<ContextProvider
>());