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 CC_SURFACES_DISPLAY_H_
6#define CC_SURFACES_DISPLAY_H_
7
8#include "base/memory/scoped_ptr.h"
9#include "cc/output/output_surface_client.h"
10#include "cc/output/renderer.h"
11#include "cc/resources/returned_resource.h"
12#include "cc/surfaces/surface_aggregator.h"
13#include "cc/surfaces/surface_id.h"
14#include "cc/surfaces/surface_manager.h"
15#include "cc/surfaces/surfaces_export.h"
16
17namespace gfx {
18class Size;
19}
20
21namespace cc {
22
23class BlockingTaskRunner;
24class DirectRenderer;
25class DisplayClient;
26class OutputSurface;
27class ResourceProvider;
28class SharedBitmapManager;
29class Surface;
30class SurfaceAggregator;
31class SurfaceIdAllocator;
32class SurfaceFactory;
33
34// A Display produces a surface that can be used to draw to a physical display
35// (OutputSurface). The client is responsible for creating and sizing the
36// surface IDs used to draw into the display and deciding when to draw.
37class CC_SURFACES_EXPORT Display : public OutputSurfaceClient,
38                                   public RendererClient,
39                                   public SurfaceDamageObserver {
40 public:
41  Display(DisplayClient* client,
42          SurfaceManager* manager,
43          SharedBitmapManager* bitmap_manager);
44  virtual ~Display();
45
46  void Resize(SurfaceId id, const gfx::Size& new_size);
47  bool Draw();
48
49  SurfaceId CurrentSurfaceId();
50  int GetMaxFramesPending();
51
52  // OutputSurfaceClient implementation.
53  virtual void DeferredInitialize() OVERRIDE {}
54  virtual void ReleaseGL() OVERRIDE {}
55  virtual void CommitVSyncParameters(base::TimeTicks timebase,
56                                     base::TimeDelta interval) OVERRIDE;
57  virtual void SetNeedsRedrawRect(const gfx::Rect& damage_rect) OVERRIDE {}
58  virtual void BeginFrame(const BeginFrameArgs& args) OVERRIDE {}
59  virtual void DidSwapBuffers() OVERRIDE;
60  virtual void DidSwapBuffersComplete() OVERRIDE;
61  virtual void ReclaimResources(const CompositorFrameAck* ack) OVERRIDE {}
62  virtual void DidLoseOutputSurface() OVERRIDE {}
63  virtual void SetExternalDrawConstraints(
64      const gfx::Transform& transform,
65      const gfx::Rect& viewport,
66      const gfx::Rect& clip,
67      const gfx::Rect& viewport_rect_for_tile_priority,
68      const gfx::Transform& transform_for_tile_priority,
69      bool resourceless_software_draw) OVERRIDE {}
70  virtual void SetMemoryPolicy(const ManagedMemoryPolicy& policy) OVERRIDE {}
71  virtual void SetTreeActivationCallback(
72      const base::Closure& callback) OVERRIDE {}
73
74  // RendererClient implementation.
75  virtual void SetFullRootLayerDamage() OVERRIDE {}
76
77  // SurfaceDamageObserver implementation.
78  virtual void OnSurfaceDamaged(SurfaceId surface) OVERRIDE;
79
80 private:
81  void InitializeOutputSurface();
82
83  DisplayClient* client_;
84  SurfaceManager* manager_;
85  SharedBitmapManager* bitmap_manager_;
86  SurfaceId current_surface_id_;
87  gfx::Size current_surface_size_;
88  LayerTreeSettings settings_;
89  scoped_ptr<OutputSurface> output_surface_;
90  scoped_ptr<ResourceProvider> resource_provider_;
91  scoped_ptr<SurfaceAggregator> aggregator_;
92  scoped_ptr<DirectRenderer> renderer_;
93  scoped_ptr<BlockingTaskRunner> blocking_main_thread_task_runner_;
94
95  DISALLOW_COPY_AND_ASSIGN(Display);
96};
97
98}  // namespace cc
99
100#endif  // CC_SURFACES_DISPLAY_H_
101