Home | History | Annotate | Download | only in layers
      1 // Copyright 2011 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_LAYERS_RENDER_SURFACE_IMPL_H_
      6 #define CC_LAYERS_RENDER_SURFACE_IMPL_H_
      7 
      8 #include <string>
      9 #include <vector>
     10 
     11 #include "base/basictypes.h"
     12 #include "base/memory/scoped_ptr.h"
     13 #include "cc/base/cc_export.h"
     14 #include "cc/layers/layer_lists.h"
     15 #include "cc/quads/render_pass.h"
     16 #include "cc/quads/shared_quad_state.h"
     17 #include "ui/gfx/rect.h"
     18 #include "ui/gfx/rect_f.h"
     19 #include "ui/gfx/transform.h"
     20 
     21 namespace cc {
     22 
     23 class DamageTracker;
     24 class DelegatedRendererLayerImpl;
     25 class QuadSink;
     26 class RenderPassSink;
     27 class LayerImpl;
     28 template <typename LayerType>
     29 class LayerIterator;
     30 
     31 struct AppendQuadsData;
     32 
     33 class CC_EXPORT RenderSurfaceImpl {
     34  public:
     35   explicit RenderSurfaceImpl(LayerImpl* owning_layer);
     36   virtual ~RenderSurfaceImpl();
     37 
     38   gfx::PointF ContentRectCenter() const {
     39     return gfx::RectF(content_rect_).CenterPoint();
     40   }
     41 
     42   // Returns the rect that encloses the RenderSurfaceImpl including any
     43   // reflection.
     44   gfx::RectF DrawableContentRect() const;
     45 
     46   void SetDrawOpacity(float opacity) { draw_opacity_ = opacity; }
     47   float draw_opacity() const { return draw_opacity_; }
     48 
     49   void SetNearestOcclusionImmuneAncestor(RenderSurfaceImpl* surface) {
     50     nearest_occlusion_immune_ancestor_ = surface;
     51   }
     52   const RenderSurfaceImpl* nearest_occlusion_immune_ancestor() const {
     53     return nearest_occlusion_immune_ancestor_;
     54   }
     55 
     56   void SetDrawOpacityIsAnimating(bool draw_opacity_is_animating) {
     57     draw_opacity_is_animating_ = draw_opacity_is_animating;
     58   }
     59   bool draw_opacity_is_animating() const { return draw_opacity_is_animating_; }
     60 
     61   void SetDrawTransform(const gfx::Transform& draw_transform) {
     62     draw_transform_ = draw_transform;
     63   }
     64   const gfx::Transform& draw_transform() const { return draw_transform_; }
     65 
     66   void SetScreenSpaceTransform(const gfx::Transform& screen_space_transform) {
     67     screen_space_transform_ = screen_space_transform;
     68   }
     69   const gfx::Transform& screen_space_transform() const {
     70     return screen_space_transform_;
     71   }
     72 
     73   void SetReplicaDrawTransform(const gfx::Transform& replica_draw_transform) {
     74     replica_draw_transform_ = replica_draw_transform;
     75   }
     76   const gfx::Transform& replica_draw_transform() const {
     77     return replica_draw_transform_;
     78   }
     79 
     80   void SetReplicaScreenSpaceTransform(
     81       const gfx::Transform& replica_screen_space_transform) {
     82     replica_screen_space_transform_ = replica_screen_space_transform;
     83   }
     84   const gfx::Transform& replica_screen_space_transform() const {
     85     return replica_screen_space_transform_;
     86   }
     87 
     88   void SetTargetSurfaceTransformsAreAnimating(bool animating) {
     89     target_surface_transforms_are_animating_ = animating;
     90   }
     91   bool target_surface_transforms_are_animating() const {
     92     return target_surface_transforms_are_animating_;
     93   }
     94   void SetScreenSpaceTransformsAreAnimating(bool animating) {
     95     screen_space_transforms_are_animating_ = animating;
     96   }
     97   bool screen_space_transforms_are_animating() const {
     98     return screen_space_transforms_are_animating_;
     99   }
    100 
    101   void SetIsClipped(bool is_clipped) { is_clipped_ = is_clipped; }
    102   bool is_clipped() const { return is_clipped_; }
    103 
    104   void SetClipRect(const gfx::Rect& clip_rect);
    105   gfx::Rect clip_rect() const { return clip_rect_; }
    106 
    107   // When false, the RenderSurface does not contribute to another target
    108   // RenderSurface that is being drawn for the current frame. It could still be
    109   // drawn to as a target, but its output will not be a part of any other
    110   // surface.
    111   bool contributes_to_drawn_surface() const {
    112     return contributes_to_drawn_surface_;
    113   }
    114   void set_contributes_to_drawn_surface(bool contributes_to_drawn_surface) {
    115     contributes_to_drawn_surface_ = contributes_to_drawn_surface;
    116   }
    117 
    118   bool ContentsChanged() const;
    119 
    120   void SetContentRect(const gfx::Rect& content_rect);
    121   gfx::Rect content_rect() const { return content_rect_; }
    122 
    123   LayerImplList& layer_list() { return layer_list_; }
    124   void AddContributingDelegatedRenderPassLayer(LayerImpl* layer);
    125   void ClearLayerLists();
    126 
    127   int OwningLayerId() const;
    128 
    129   void ResetPropertyChangedFlag() { surface_property_changed_ = false; }
    130   bool SurfacePropertyChanged() const;
    131   bool SurfacePropertyChangedOnlyFromDescendant() const;
    132 
    133   DamageTracker* damage_tracker() const { return damage_tracker_.get(); }
    134 
    135   RenderPass::Id RenderPassId();
    136 
    137   void AppendRenderPasses(RenderPassSink* pass_sink);
    138   void AppendQuads(QuadSink* quad_sink,
    139                    AppendQuadsData* append_quads_data,
    140                    bool for_replica,
    141                    RenderPass::Id render_pass_id);
    142 
    143  private:
    144   LayerImpl* owning_layer_;
    145 
    146   // Uses this surface's space.
    147   gfx::Rect content_rect_;
    148   bool surface_property_changed_ : 1;
    149   bool draw_opacity_is_animating_ : 1;
    150   bool target_surface_transforms_are_animating_ : 1;
    151   bool screen_space_transforms_are_animating_ : 1;
    152 
    153   bool is_clipped_ : 1;
    154   bool contributes_to_drawn_surface_ : 1;
    155 
    156   float draw_opacity_;
    157   gfx::Transform draw_transform_;
    158   gfx::Transform screen_space_transform_;
    159   gfx::Transform replica_draw_transform_;
    160   gfx::Transform replica_screen_space_transform_;
    161 
    162   // Uses the space of the surface's target surface.
    163   gfx::Rect clip_rect_;
    164 
    165   LayerImplList layer_list_;
    166   std::vector<DelegatedRendererLayerImpl*>
    167       contributing_delegated_render_pass_layer_list_;
    168 
    169   // The nearest ancestor target surface that will contain the contents of this
    170   // surface, and that ignores outside occlusion. This can point to itself.
    171   RenderSurfaceImpl* nearest_occlusion_immune_ancestor_;
    172 
    173   scoped_ptr<DamageTracker> damage_tracker_;
    174 
    175   // For LayerIteratorActions
    176   int target_render_surface_layer_index_history_;
    177   int current_layer_index_history_;
    178 
    179   friend class LayerIterator<LayerImpl>;
    180 
    181   DISALLOW_COPY_AND_ASSIGN(RenderSurfaceImpl);
    182 };
    183 
    184 }  // namespace cc
    185 #endif  // CC_LAYERS_RENDER_SURFACE_IMPL_H_
    186