Home | History | Annotate | Download | only in trees
      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_TREES_LAYER_TREE_IMPL_H_
      6 #define CC_TREES_LAYER_TREE_IMPL_H_
      7 
      8 #include <list>
      9 #include <string>
     10 #include <vector>
     11 
     12 #include "base/containers/hash_tables.h"
     13 #include "base/values.h"
     14 #include "cc/layers/layer_impl.h"
     15 #include "cc/resources/ui_resource_client.h"
     16 #include "ui/base/latency_info.h"
     17 
     18 #if defined(COMPILER_GCC)
     19 namespace BASE_HASH_NAMESPACE {
     20 template<>
     21 struct hash<cc::LayerImpl*> {
     22   size_t operator()(cc::LayerImpl* ptr) const {
     23     return hash<size_t>()(reinterpret_cast<size_t>(ptr));
     24   }
     25 };
     26 }  // namespace BASE_HASH_NAMESPACE
     27 #endif  // COMPILER
     28 
     29 namespace cc {
     30 
     31 class DebugRectHistory;
     32 class FrameRateCounter;
     33 class HeadsUpDisplayLayerImpl;
     34 class LayerTreeDebugState;
     35 class LayerTreeHostImpl;
     36 class LayerTreeImpl;
     37 class LayerTreeSettings;
     38 class MemoryHistory;
     39 class OutputSurface;
     40 class PaintTimeCounter;
     41 class Proxy;
     42 class ResourceProvider;
     43 class TileManager;
     44 struct RendererCapabilities;
     45 struct UIResourceRequest;
     46 
     47 typedef std::list<UIResourceRequest> UIResourceRequestQueue;
     48 
     49 class CC_EXPORT LayerTreeImpl {
     50  public:
     51   static scoped_ptr<LayerTreeImpl> create(
     52       LayerTreeHostImpl* layer_tree_host_impl) {
     53     return make_scoped_ptr(new LayerTreeImpl(layer_tree_host_impl));
     54   }
     55   virtual ~LayerTreeImpl();
     56 
     57   // Methods called by the layer tree that pass-through or access LTHI.
     58   // ---------------------------------------------------------------------------
     59   const LayerTreeSettings& settings() const;
     60   const RendererCapabilities& GetRendererCapabilities() const;
     61   OutputSurface* output_surface() const;
     62   ResourceProvider* resource_provider() const;
     63   TileManager* tile_manager() const;
     64   FrameRateCounter* frame_rate_counter() const;
     65   PaintTimeCounter* paint_time_counter() const;
     66   MemoryHistory* memory_history() const;
     67   bool IsActiveTree() const;
     68   bool IsPendingTree() const;
     69   bool IsRecycleTree() const;
     70   LayerImpl* FindActiveTreeLayerById(int id);
     71   LayerImpl* FindPendingTreeLayerById(int id);
     72   int MaxTextureSize() const;
     73   bool PinchGestureActive() const;
     74   base::TimeTicks CurrentFrameTimeTicks() const;
     75   base::Time CurrentFrameTime() const;
     76   base::TimeTicks CurrentPhysicalTimeTicks() const;
     77   void SetNeedsCommit();
     78   gfx::Rect DeviceViewport() const;
     79   bool DeviceViewportValidForTileManagement() const;
     80 
     81   // Tree specific methods exposed to layer-impl tree.
     82   // ---------------------------------------------------------------------------
     83   void SetNeedsRedraw();
     84 
     85   // TODO(nduca): These are implemented in cc files temporarily, but will become
     86   // trivial accessors in a followup patch.
     87   const LayerTreeDebugState& debug_state() const;
     88   float device_scale_factor() const;
     89   DebugRectHistory* debug_rect_history() const;
     90   scoped_ptr<base::Value> AsValue() const;
     91 
     92   // Other public methods
     93   // ---------------------------------------------------------------------------
     94   LayerImpl* root_layer() const { return root_layer_.get(); }
     95   void SetRootLayer(scoped_ptr<LayerImpl>);
     96   scoped_ptr<LayerImpl> DetachLayerTree();
     97 
     98   void PushPropertiesTo(LayerTreeImpl* tree_impl);
     99 
    100   int source_frame_number() const { return source_frame_number_; }
    101   void set_source_frame_number(int frame_number) {
    102     source_frame_number_ = frame_number;
    103   }
    104 
    105   HeadsUpDisplayLayerImpl* hud_layer() { return hud_layer_; }
    106   void set_hud_layer(HeadsUpDisplayLayerImpl* layer_impl) {
    107     hud_layer_ = layer_impl;
    108   }
    109 
    110   LayerImpl* RootScrollLayer() const;
    111   LayerImpl* RootContainerLayer() const;
    112   LayerImpl* CurrentlyScrollingLayer() const;
    113   void SetCurrentlyScrollingLayer(LayerImpl* layer);
    114   void ClearCurrentlyScrollingLayer();
    115 
    116   void FindRootScrollLayer();
    117   void UpdateMaxScrollOffset();
    118   void ApplySentScrollAndScaleDeltas();
    119 
    120   SkColor background_color() const { return background_color_; }
    121   void set_background_color(SkColor color) { background_color_ = color; }
    122 
    123   bool has_transparent_background() const {
    124     return has_transparent_background_;
    125   }
    126   void set_has_transparent_background(bool transparent) {
    127     has_transparent_background_ = transparent;
    128   }
    129 
    130   void SetPageScaleFactorAndLimits(float page_scale_factor,
    131       float min_page_scale_factor, float max_page_scale_factor);
    132   void SetPageScaleDelta(float delta);
    133   float total_page_scale_factor() const {
    134     return page_scale_factor_ * page_scale_delta_;
    135   }
    136   float page_scale_factor() const { return page_scale_factor_; }
    137   float min_page_scale_factor() const { return min_page_scale_factor_; }
    138   float max_page_scale_factor() const { return max_page_scale_factor_; }
    139   float page_scale_delta() const  { return page_scale_delta_; }
    140   void set_sent_page_scale_delta(float delta) {
    141     sent_page_scale_delta_ = delta;
    142   }
    143   float sent_page_scale_delta() const { return sent_page_scale_delta_; }
    144 
    145   // Updates draw properties and render surface layer list, as well as tile
    146   // priorities.
    147   void UpdateDrawProperties();
    148 
    149   void set_needs_update_draw_properties() {
    150     needs_update_draw_properties_ = true;
    151   }
    152   bool needs_update_draw_properties() const {
    153     return needs_update_draw_properties_;
    154   }
    155 
    156   void set_needs_full_tree_sync(bool needs) { needs_full_tree_sync_ = needs; }
    157   bool needs_full_tree_sync() const { return needs_full_tree_sync_; }
    158 
    159   void set_ui_resource_request_queue(const UIResourceRequestQueue& queue);
    160 
    161   const LayerImplList& RenderSurfaceLayerList() const;
    162 
    163   // These return the size of the root scrollable area and the size of
    164   // the user-visible scrolling viewport, in CSS layout coordinates.
    165   gfx::Size ScrollableSize() const;
    166   gfx::SizeF ScrollableViewportSize() const;
    167 
    168   LayerImpl* LayerById(int id);
    169 
    170   // These should be called by LayerImpl's ctor/dtor.
    171   void RegisterLayer(LayerImpl* layer);
    172   void UnregisterLayer(LayerImpl* layer);
    173 
    174   AnimationRegistrar* animationRegistrar() const;
    175 
    176   void PushPersistedState(LayerTreeImpl* pending_tree);
    177 
    178   void DidBecomeActive();
    179 
    180   bool ContentsTexturesPurged() const;
    181   void SetContentsTexturesPurged();
    182   void ResetContentsTexturesPurged();
    183 
    184   // Set on the active tree when the viewport size recently changed
    185   // and the active tree's size is now out of date.
    186   bool ViewportSizeInvalid() const;
    187   void SetViewportSizeInvalid();
    188   void ResetViewportSizeInvalid();
    189 
    190   // Useful for debug assertions, probably shouldn't be used for anything else.
    191   Proxy* proxy() const;
    192 
    193   void SetRootLayerScrollOffsetDelegate(
    194       LayerScrollOffsetDelegate* root_layer_scroll_offset_delegate);
    195 
    196   void SetLatencyInfo(const ui::LatencyInfo& latency_info);
    197   const ui::LatencyInfo& GetLatencyInfo();
    198   void ClearLatencyInfo();
    199 
    200   void WillModifyTilePriorities();
    201 
    202   ResourceProvider::ResourceId ResourceIdForUIResource(UIResourceId uid) const;
    203   void ProcessUIResourceRequestQueue();
    204 
    205   void AddLayerWithCopyOutputRequest(LayerImpl* layer);
    206   void RemoveLayerWithCopyOutputRequest(LayerImpl* layer);
    207   const std::vector<LayerImpl*> LayersWithCopyOutputRequest() const;
    208 
    209  protected:
    210   explicit LayerTreeImpl(LayerTreeHostImpl* layer_tree_host_impl);
    211 
    212   void UpdateSolidColorScrollbars();
    213 
    214   void UpdateRootScrollLayerSizeDelta();
    215 
    216   LayerTreeHostImpl* layer_tree_host_impl_;
    217   int source_frame_number_;
    218   scoped_ptr<LayerImpl> root_layer_;
    219   HeadsUpDisplayLayerImpl* hud_layer_;
    220   LayerImpl* root_scroll_layer_;
    221   LayerImpl* currently_scrolling_layer_;
    222   LayerScrollOffsetDelegate* root_layer_scroll_offset_delegate_;
    223   SkColor background_color_;
    224   bool has_transparent_background_;
    225 
    226   float page_scale_factor_;
    227   float page_scale_delta_;
    228   float sent_page_scale_delta_;
    229   float min_page_scale_factor_;
    230   float max_page_scale_factor_;
    231 
    232   typedef base::hash_map<int, LayerImpl*> LayerIdMap;
    233   LayerIdMap layer_id_map_;
    234 
    235   std::vector<LayerImpl*> layers_with_copy_output_request_;
    236 
    237   // Persisted state for non-impl-side-painting.
    238   int scrolling_layer_id_from_previous_tree_;
    239 
    240   // List of visible layers for the most recently prepared frame. Used for
    241   // rendering and input event hit testing.
    242   LayerImplList render_surface_layer_list_;
    243 
    244   bool contents_textures_purged_;
    245   bool viewport_size_invalid_;
    246   bool needs_update_draw_properties_;
    247 
    248   // In impl-side painting mode, this is true when the tree may contain
    249   // structural differences relative to the active tree.
    250   bool needs_full_tree_sync_;
    251 
    252   ui::LatencyInfo latency_info_;
    253 
    254   UIResourceRequestQueue ui_resource_request_queue_;
    255 
    256  private:
    257   DISALLOW_COPY_AND_ASSIGN(LayerTreeImpl);
    258 };
    259 
    260 }  // namespace cc
    261 
    262 #endif  // CC_TREES_LAYER_TREE_IMPL_H_
    263