render_surface.h revision 7dbb3d5cf0c15f500944d211057644d6a2f37371
1// Copyright 2010 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
6#ifndef CC_LAYERS_RENDER_SURFACE_H_
7#define CC_LAYERS_RENDER_SURFACE_H_
8
9#include <vector>
10
11#include "base/basictypes.h"
12#include "base/memory/ref_counted.h"
13#include "cc/base/cc_export.h"
14#include "cc/layers/layer_lists.h"
15#include "ui/gfx/rect.h"
16#include "ui/gfx/rect_f.h"
17#include "ui/gfx/transform.h"
18
19namespace cc {
20
21class Layer;
22
23class CC_EXPORT RenderSurface {
24 public:
25  explicit RenderSurface(Layer* owning_layer);
26  ~RenderSurface();
27
28  // Returns the rect that encloses the RenderSurfaceImpl including any
29  // reflection.
30  gfx::RectF DrawableContentRect() const;
31
32  void SetContentRect(gfx::Rect content_rect) { content_rect_ = content_rect; }
33  gfx::Rect content_rect() const { return content_rect_; }
34
35  void SetDrawOpacity(float opacity) { draw_opacity_ = opacity; }
36  float draw_opacity() const { return draw_opacity_; }
37
38  void SetDrawOpacityIsAnimating(bool draw_opacity_is_animating) {
39    draw_opacity_is_animating_ = draw_opacity_is_animating;
40  }
41  bool draw_opacity_is_animating() const { return draw_opacity_is_animating_; }
42
43  void SetDrawTransform(const gfx::Transform& draw_transform) {
44    draw_transform_ = draw_transform;
45  }
46  const gfx::Transform& draw_transform() const { return draw_transform_; }
47
48  void SetScreenSpaceTransform(const gfx::Transform& screen_space_transform) {
49    screen_space_transform_ = screen_space_transform;
50  }
51  const gfx::Transform& screen_space_transform() const {
52    return screen_space_transform_;
53  }
54
55  void SetReplicaDrawTransform(const gfx::Transform& replica_draw_transform) {
56    replica_draw_transform_ = replica_draw_transform;
57  }
58  const gfx::Transform& replica_draw_transform() const {
59    return replica_draw_transform_;
60  }
61
62  void SetReplicaScreenSpaceTransform(
63      const gfx::Transform& replica_screen_space_transform) {
64    replica_screen_space_transform_ = replica_screen_space_transform;
65  }
66  const gfx::Transform& replica_screen_space_transform() const {
67    return replica_screen_space_transform_;
68  }
69
70  void SetTargetSurfaceTransformsAreAnimating(bool animating) {
71    target_surface_transforms_are_animating_ = animating;
72  }
73  bool target_surface_transforms_are_animating() const {
74    return target_surface_transforms_are_animating_;
75  }
76  void SetScreenSpaceTransformsAreAnimating(bool animating) {
77    screen_space_transforms_are_animating_ = animating;
78  }
79  bool screen_space_transforms_are_animating() const {
80    return screen_space_transforms_are_animating_;
81  }
82
83  bool is_clipped() const { return is_clipped_; }
84  void SetIsClipped(bool is_clipped) { is_clipped_ = is_clipped; }
85
86  gfx::Rect clip_rect() const { return clip_rect_; }
87  void SetClipRect(gfx::Rect clip_rect) { clip_rect_ = clip_rect; }
88
89  // When false, the RenderSurface does not contribute to another target
90  // RenderSurface that is being drawn for the current frame. It could still be
91  // drawn to as a target, but its output will not be a part of any other
92  // surface.
93  bool contributes_to_drawn_surface() const {
94    return contributes_to_drawn_surface_;
95  }
96  void set_contributes_to_drawn_surface(bool contributes_to_drawn_surface) {
97    contributes_to_drawn_surface_ = contributes_to_drawn_surface;
98  }
99
100  LayerList& layer_list() { return layer_list_; }
101  // A no-op since DelegatedRendererLayers on the main thread don't have any
102  // RenderPasses so they can't contribute to a surface.
103  void AddContributingDelegatedRenderPassLayer(Layer* layer) {}
104  void ClearLayerLists() { layer_list_.clear(); }
105
106  void SetNearestAncestorThatMovesPixels(RenderSurface* surface) {
107    nearest_ancestor_that_moves_pixels_ = surface;
108  }
109  const RenderSurface* nearest_ancestor_that_moves_pixels() const {
110    return nearest_ancestor_that_moves_pixels_;
111  }
112
113 private:
114  friend struct LayerIteratorActions;
115
116  Layer* owning_layer_;
117
118  // Uses this surface's space.
119  gfx::Rect content_rect_;
120
121  float draw_opacity_;
122  bool draw_opacity_is_animating_;
123  gfx::Transform draw_transform_;
124  gfx::Transform screen_space_transform_;
125  gfx::Transform replica_draw_transform_;
126  gfx::Transform replica_screen_space_transform_;
127  bool target_surface_transforms_are_animating_;
128  bool screen_space_transforms_are_animating_;
129
130  bool is_clipped_;
131  bool contributes_to_drawn_surface_;
132
133  // Uses the space of the surface's target surface.
134  gfx::Rect clip_rect_;
135
136  LayerList layer_list_;
137
138  // The nearest ancestor target surface that will contain the contents of this
139  // surface, and that is going to move pixels within the surface (such as with
140  // a blur). This can point to itself.
141  RenderSurface* nearest_ancestor_that_moves_pixels_;
142
143  // For LayerIteratorActions
144  int target_render_surface_layer_index_history_;
145  int current_layer_index_history_;
146
147  DISALLOW_COPY_AND_ASSIGN(RenderSurface);
148};
149
150}  // namespace cc
151#endif  // CC_LAYERS_RENDER_SURFACE_H_
152