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