fake_output_surface.h revision 7dbb3d5cf0c15f500944d211057644d6a2f37371
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#ifndef CC_TEST_FAKE_OUTPUT_SURFACE_H_ 6#define CC_TEST_FAKE_OUTPUT_SURFACE_H_ 7 8#include "base/time/time.h" 9#include "cc/output/begin_frame_args.h" 10#include "cc/output/compositor_frame.h" 11#include "cc/output/output_surface.h" 12#include "cc/output/software_output_device.h" 13#include "cc/test/test_web_graphics_context_3d.h" 14#include "third_party/WebKit/public/platform/WebGraphicsContext3D.h" 15 16namespace cc { 17 18class FakeOutputSurface : public OutputSurface { 19 public: 20 virtual ~FakeOutputSurface(); 21 22 static scoped_ptr<FakeOutputSurface> Create3d( 23 scoped_ptr<WebKit::WebGraphicsContext3D> context3d) { 24 return make_scoped_ptr(new FakeOutputSurface(context3d.Pass(), false)); 25 } 26 27 static scoped_ptr<FakeOutputSurface> Create3d() { 28 scoped_ptr<WebKit::WebGraphicsContext3D> context3d = 29 TestWebGraphicsContext3D::Create() 30 .PassAs<WebKit::WebGraphicsContext3D>(); 31 return make_scoped_ptr(new FakeOutputSurface(context3d.Pass(), false)); 32 } 33 34 static scoped_ptr<FakeOutputSurface> CreateSoftware( 35 scoped_ptr<SoftwareOutputDevice> software_device) { 36 return make_scoped_ptr( 37 new FakeOutputSurface(software_device.Pass(), false)); 38 } 39 40 static scoped_ptr<FakeOutputSurface> CreateDelegating3d( 41 scoped_ptr<WebKit::WebGraphicsContext3D> context3d) { 42 return make_scoped_ptr(new FakeOutputSurface(context3d.Pass(), true)); 43 } 44 45 static scoped_ptr<FakeOutputSurface> CreateDelegating3d() { 46 scoped_ptr<WebKit::WebGraphicsContext3D> context3d = 47 TestWebGraphicsContext3D::Create() 48 .PassAs<WebKit::WebGraphicsContext3D>(); 49 return make_scoped_ptr(new FakeOutputSurface(context3d.Pass(), true)); 50 } 51 52 static scoped_ptr<FakeOutputSurface> CreateDelegatingSoftware( 53 scoped_ptr<SoftwareOutputDevice> software_device) { 54 return make_scoped_ptr( 55 new FakeOutputSurface(software_device.Pass(), true)); 56 } 57 58 static scoped_ptr<FakeOutputSurface> CreateDeferredGL( 59 scoped_ptr<SoftwareOutputDevice> software_device) { 60 scoped_ptr<FakeOutputSurface> result( 61 new FakeOutputSurface(software_device.Pass(), false)); 62 result->capabilities_.deferred_gl_initialization = true; 63 return result.Pass(); 64 } 65 66 CompositorFrame& last_sent_frame() { return last_sent_frame_; } 67 size_t num_sent_frames() { return num_sent_frames_; } 68 69 virtual void SwapBuffers(CompositorFrame* frame) OVERRIDE; 70 71 virtual void SetNeedsBeginFrame(bool enable) OVERRIDE; 72 bool needs_begin_frame() const { 73 return needs_begin_frame_; 74 } 75 76 void set_forced_draw_to_software_device(bool forced) { 77 forced_draw_to_software_device_ = forced; 78 } 79 virtual bool ForcedDrawToSoftwareDevice() const OVERRIDE; 80 81 bool SetAndInitializeContext3D( 82 scoped_ptr<WebKit::WebGraphicsContext3D> context3d); 83 84 using OutputSurface::ReleaseGL; 85 86 protected: 87 FakeOutputSurface( 88 scoped_ptr<WebKit::WebGraphicsContext3D> context3d, 89 bool delegated_rendering); 90 91 FakeOutputSurface( 92 scoped_ptr<SoftwareOutputDevice> software_device, 93 bool delegated_rendering); 94 95 FakeOutputSurface( 96 scoped_ptr<WebKit::WebGraphicsContext3D> context3d, 97 scoped_ptr<SoftwareOutputDevice> software_device, 98 bool delegated_rendering); 99 100 void OnBeginFrame(); 101 102 CompositorFrame last_sent_frame_; 103 size_t num_sent_frames_; 104 bool needs_begin_frame_; 105 bool forced_draw_to_software_device_; 106 base::WeakPtrFactory<FakeOutputSurface> fake_weak_ptr_factory_; 107}; 108 109static inline scoped_ptr<cc::OutputSurface> CreateFakeOutputSurface() { 110 return FakeOutputSurface::Create3d().PassAs<cc::OutputSurface>(); 111} 112 113} // namespace cc 114 115#endif // CC_TEST_FAKE_OUTPUT_SURFACE_H_ 116