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 
     23 class 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   RenderSurfaceLayerList& 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 
    105   void SetNearestAncestorThatMovesPixels(RenderSurface* surface) {
    106     nearest_ancestor_that_moves_pixels_ = surface;
    107   }
    108   const RenderSurface* nearest_ancestor_that_moves_pixels() const {
    109     return nearest_ancestor_that_moves_pixels_;
    110   }
    111 
    112  private:
    113   friend struct LayerIteratorActions;
    114 
    115   Layer* owning_layer_;
    116 
    117   // Uses this surface's space.
    118   gfx::Rect content_rect_;
    119 
    120   float draw_opacity_;
    121   bool draw_opacity_is_animating_;
    122   gfx::Transform draw_transform_;
    123   gfx::Transform screen_space_transform_;
    124   gfx::Transform replica_draw_transform_;
    125   gfx::Transform replica_screen_space_transform_;
    126   bool target_surface_transforms_are_animating_;
    127   bool screen_space_transforms_are_animating_;
    128 
    129   bool is_clipped_;
    130   bool contributes_to_drawn_surface_;
    131 
    132   // Uses the space of the surface's target surface.
    133   gfx::Rect clip_rect_;
    134 
    135   RenderSurfaceLayerList layer_list_;
    136 
    137   // The nearest ancestor target surface that will contain the contents of this
    138   // surface, and that is going to move pixels within the surface (such as with
    139   // a blur). This can point to itself.
    140   RenderSurface* nearest_ancestor_that_moves_pixels_;
    141 
    142   // For LayerIteratorActions
    143   int target_render_surface_layer_index_history_;
    144   int current_layer_index_history_;
    145 
    146   DISALLOW_COPY_AND_ASSIGN(RenderSurface);
    147 };
    148 
    149 }  // namespace cc
    150 #endif  // CC_LAYERS_RENDER_SURFACE_H_
    151