fake_output_surface.cc revision 5e3f23d412006dc4db4e659864679f29341e113f
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.h" 9#include "cc/output/compositor_frame_ack.h" 10#include "cc/output/output_surface_client.h" 11 12namespace cc { 13 14FakeOutputSurface::FakeOutputSurface( 15 scoped_ptr<WebKit::WebGraphicsContext3D> context3d, 16 bool delegated_rendering) 17 : OutputSurface(context3d.Pass()), 18 num_sent_frames_(0), 19 needs_begin_frame_(false), 20 forced_draw_to_software_device_(false) { 21 if (delegated_rendering) { 22 capabilities_.delegated_rendering = true; 23 capabilities_.max_frames_pending = 1; 24 } 25} 26 27FakeOutputSurface::FakeOutputSurface( 28 scoped_ptr<SoftwareOutputDevice> software_device, bool delegated_rendering) 29 : OutputSurface(software_device.Pass()), 30 num_sent_frames_(0), 31 forced_draw_to_software_device_(false) { 32 if (delegated_rendering) { 33 capabilities_.delegated_rendering = true; 34 capabilities_.max_frames_pending = 1; 35 } 36} 37 38FakeOutputSurface::FakeOutputSurface( 39 scoped_ptr<WebKit::WebGraphicsContext3D> context3d, 40 scoped_ptr<SoftwareOutputDevice> software_device, 41 bool delegated_rendering) 42 : OutputSurface(context3d.Pass(), software_device.Pass()), 43 num_sent_frames_(0), 44 forced_draw_to_software_device_(false) { 45 if (delegated_rendering) { 46 capabilities_.delegated_rendering = true; 47 capabilities_.max_frames_pending = 1; 48 } 49} 50 51FakeOutputSurface::~FakeOutputSurface() {} 52 53void FakeOutputSurface::SwapBuffers(CompositorFrame* frame) { 54 if (frame->software_frame_data || frame->delegated_frame_data || 55 !context3d()) { 56 frame->AssignTo(&last_sent_frame_); 57 ++num_sent_frames_; 58 PostSwapBuffersComplete(); 59 } else { 60 OutputSurface::SwapBuffers(frame); 61 frame->AssignTo(&last_sent_frame_); 62 ++num_sent_frames_; 63 } 64} 65 66void FakeOutputSurface::SetNeedsBeginFrame(bool enable) { 67 needs_begin_frame_ = enable; 68} 69 70void FakeOutputSurface::BeginFrame(base::TimeTicks frame_time) { 71 client_->BeginFrame(frame_time); 72} 73 74bool FakeOutputSurface::ForcedDrawToSoftwareDevice() const { 75 return forced_draw_to_software_device_; 76} 77 78} // namespace cc 79