1 // Copyright 2014 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 CONTENT_BROWSER_COMPOSITOR_ONSCREEN_DISPLAY_CLIENT_H_ 6 #define CONTENT_BROWSER_COMPOSITOR_ONSCREEN_DISPLAY_CLIENT_H_ 7 8 #include "cc/surfaces/display_client.h" 9 10 #include "base/memory/ref_counted.h" 11 #include "base/memory/scoped_ptr.h" 12 #include "base/single_thread_task_runner.h" 13 #include "cc/surfaces/display.h" 14 15 namespace cc { 16 class ContextProvider; 17 class SurfaceManager; 18 } 19 20 namespace content { 21 class SurfaceDisplayOutputSurface; 22 23 // This class provides a DisplayClient implementation for drawing directly to an 24 // onscreen context. 25 class OnscreenDisplayClient : cc::DisplayClient { 26 public: 27 OnscreenDisplayClient( 28 scoped_ptr<cc::OutputSurface> output_surface, 29 cc::SurfaceManager* manager, 30 scoped_refptr<base::SingleThreadTaskRunner> task_runner); 31 virtual ~OnscreenDisplayClient(); 32 display()33 cc::Display* display() { return display_.get(); } set_surface_output_surface(SurfaceDisplayOutputSurface * surface)34 void set_surface_output_surface(SurfaceDisplayOutputSurface* surface) { 35 surface_display_output_surface_ = surface; 36 } 37 38 // cc::DisplayClient implementation. 39 virtual scoped_ptr<cc::OutputSurface> CreateOutputSurface() OVERRIDE; 40 virtual void DisplayDamaged() OVERRIDE; 41 virtual void DidSwapBuffers() OVERRIDE; 42 virtual void DidSwapBuffersComplete() OVERRIDE; 43 virtual void CommitVSyncParameters(base::TimeTicks timebase, 44 base::TimeDelta interval) OVERRIDE; 45 46 private: 47 void ScheduleDraw(); 48 void Draw(); 49 50 scoped_ptr<cc::OutputSurface> output_surface_; 51 scoped_ptr<cc::Display> display_; 52 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 53 SurfaceDisplayOutputSurface* surface_display_output_surface_; 54 bool scheduled_draw_; 55 // True if a draw should be scheduled, but it's hit the limit on max frames 56 // pending. 57 bool deferred_draw_; 58 int pending_frames_; 59 60 base::WeakPtrFactory<OnscreenDisplayClient> weak_ptr_factory_; 61 62 DISALLOW_COPY_AND_ASSIGN(OnscreenDisplayClient); 63 }; 64 65 } // namespace content 66 67 #endif // CONTENT_BROWSER_COMPOSITOR_ONSCREEN_DISPLAY_CLIENT_H_ 68