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_OUTPUT_RENDERER_H_
6#define CC_OUTPUT_RENDERER_H_
7
8#include "base/basictypes.h"
9#include "cc/base/cc_export.h"
10#include "cc/base/scoped_ptr_vector.h"
11#include "cc/trees/layer_tree_host.h"
12
13namespace cc {
14
15class CompositorFrameAck;
16class CompositorFrameMetadata;
17class RenderPass;
18class RenderPassId;
19class ScopedResource;
20class Task;
21
22typedef ScopedPtrVector<RenderPass> RenderPassList;
23
24struct RendererCapabilitiesImpl {
25  RendererCapabilitiesImpl();
26  ~RendererCapabilitiesImpl();
27
28  // Capabilities copied to main thread.
29  ResourceFormat best_texture_format;
30  bool allow_partial_texture_updates;
31  int max_texture_size;
32  bool using_shared_memory_resources;
33
34  // Capabilities used on compositor thread only.
35  bool using_partial_swap;
36  bool using_egl_image;
37  bool using_map_image;
38  bool using_discard_framebuffer;
39  bool allow_rasterize_on_demand;
40
41  RendererCapabilities MainThreadCapabilities() const;
42};
43
44class CC_EXPORT RendererClient {
45 public:
46  virtual void SetFullRootLayerDamage() = 0;
47};
48
49class CC_EXPORT Renderer {
50 public:
51  virtual ~Renderer() {}
52
53  virtual const RendererCapabilitiesImpl& Capabilities() const = 0;
54
55  virtual void DecideRenderPassAllocationsForFrame(
56      const RenderPassList& render_passes_in_draw_order) {}
57  virtual bool HasAllocatedResourcesForTesting(RenderPassId id) const;
58
59  // This passes ownership of the render passes to the renderer. It should
60  // consume them, and empty the list. The parameters here may change from frame
61  // to frame and should not be cached.
62  // The |device_viewport_rect| and |device_clip_rect| are in non-y-flipped
63  // window space.
64  virtual void DrawFrame(RenderPassList* render_passes_in_draw_order,
65                         float device_scale_factor,
66                         const gfx::Rect& device_viewport_rect,
67                         const gfx::Rect& device_clip_rect,
68                         bool disable_picture_quad_image_filtering) = 0;
69
70  // Waits for rendering to finish.
71  virtual void Finish() = 0;
72
73  virtual void DoNoOp() {}
74
75  // Puts backbuffer onscreen.
76  virtual void SwapBuffers(const CompositorFrameMetadata& metadata) = 0;
77  virtual void ReceiveSwapBuffersAck(const CompositorFrameAck& ack) {}
78
79  bool visible() const { return visible_; }
80  void SetVisible(bool visible);
81
82 protected:
83  explicit Renderer(RendererClient* client, const LayerTreeSettings* settings)
84      : client_(client), settings_(settings), visible_(true) {}
85
86  virtual void DidChangeVisibility() = 0;
87
88  RendererClient* client_;
89  const LayerTreeSettings* settings_;
90  bool visible_;
91
92 private:
93  DISALLOW_COPY_AND_ASSIGN(Renderer);
94};
95
96}  // namespace cc
97
98#endif  // CC_OUTPUT_RENDERER_H_
99