tiled_layer.h revision eb525c5499e34cc9c4b825d6d9e75bb07cc06ace
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_TILED_LAYER_H_
6#define CC_LAYERS_TILED_LAYER_H_
7
8#include "cc/base/cc_export.h"
9#include "cc/layers/contents_scaling_layer.h"
10#include "cc/resources/layer_tiling_data.h"
11
12namespace cc {
13class LayerUpdater;
14class PrioritizedResourceManager;
15class PrioritizedResource;
16class UpdatableTile;
17
18class CC_EXPORT TiledLayer : public ContentsScalingLayer {
19 public:
20  enum TilingOption {
21    ALWAYS_TILE,
22    NEVER_TILE,
23    AUTO_TILE,
24  };
25
26  // Layer implementation.
27  virtual void SetIsMask(bool is_mask) OVERRIDE;
28  virtual void PushPropertiesTo(LayerImpl* layer) OVERRIDE;
29  virtual bool BlocksPendingCommit() const OVERRIDE;
30  virtual bool DrawsContent() const OVERRIDE;
31  virtual void ReduceMemoryUsage() OVERRIDE;
32  virtual void SetNeedsDisplayRect(const gfx::RectF& dirty_rect) OVERRIDE;
33  virtual void SetLayerTreeHost(LayerTreeHost* layer_tree_host) OVERRIDE;
34  virtual void SetTexturePriorities(const PriorityCalculator& priority_calc)
35      OVERRIDE;
36  virtual Region VisibleContentOpaqueRegion() const OVERRIDE;
37  virtual void Update(ResourceUpdateQueue* queue,
38                      const OcclusionTracker* occlusion) OVERRIDE;
39
40 protected:
41  TiledLayer();
42  virtual ~TiledLayer();
43
44  void UpdateTileSizeAndTilingOption();
45  void UpdateBounds();
46
47  // Exposed to subclasses for testing.
48  void SetTileSize(gfx::Size size);
49  void SetTextureFormat(unsigned texture_format) {
50    texture_format_ = texture_format;
51  }
52  void SetBorderTexelOption(LayerTilingData::BorderTexelOption option);
53  size_t NumPaintedTiles() { return tiler_->tiles().size(); }
54
55  virtual LayerUpdater* Updater() const = 0;
56  virtual void CreateUpdaterIfNeeded() = 0;
57
58  // Set invalidations to be potentially repainted during Update().
59  void InvalidateContentRect(gfx::Rect content_rect);
60
61  // Reset state on tiles that will be used for updating the layer.
62  void ResetUpdateState();
63
64  // After preparing an update, returns true if more painting is needed.
65  bool NeedsIdlePaint();
66  gfx::Rect IdlePaintRect();
67
68  bool SkipsDraw() const { return skips_draw_; }
69
70  // Virtual for testing
71  virtual PrioritizedResourceManager* ResourceManager() const;
72  const LayerTilingData* TilerForTesting() const { return tiler_.get(); }
73  const PrioritizedResource* ResourceAtForTesting(int i, int j) const;
74
75 private:
76  virtual scoped_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl)
77      OVERRIDE;
78
79  void CreateTilerIfNeeded();
80  void set_tiling_option(TilingOption tiling_option) {
81    tiling_option_ = tiling_option;
82  }
83
84  bool TileOnlyNeedsPartialUpdate(UpdatableTile* tile);
85  bool TileNeedsBufferedUpdate(UpdatableTile* tile);
86
87  void MarkOcclusionsAndRequestTextures(int left,
88                                        int top,
89                                        int right,
90                                        int bottom,
91                                        const OcclusionTracker* occlusion);
92
93  bool UpdateTiles(int left,
94                   int top,
95                   int right,
96                   int bottom,
97                   ResourceUpdateQueue* queue,
98                   const OcclusionTracker* occlusion,
99                   bool* did_paint);
100  bool HaveTexturesForTiles(int left,
101                            int top,
102                            int right,
103                            int bottom,
104                            bool ignore_occlusions);
105  gfx::Rect MarkTilesForUpdate(int left,
106                               int top,
107                               int right,
108                               int bottom,
109                               bool ignore_occlusions);
110  void UpdateTileTextures(gfx::Rect paint_rect,
111                          int left,
112                          int top,
113                          int right,
114                          int bottom,
115                          ResourceUpdateQueue* queue,
116                          const OcclusionTracker* occlusion);
117  void UpdateScrollPrediction();
118
119  UpdatableTile* TileAt(int i, int j) const;
120  UpdatableTile* CreateTile(int i, int j);
121
122  bool IsSmallAnimatedLayer() const;
123
124  unsigned texture_format_;
125  bool skips_draw_;
126  bool failed_update_;
127
128  // Used for predictive painting.
129  gfx::Vector2d predicted_scroll_;
130  gfx::Rect predicted_visible_rect_;
131  gfx::Rect previous_visible_rect_;
132  gfx::Size previous_content_bounds_;
133
134  TilingOption tiling_option_;
135  scoped_ptr<LayerTilingData> tiler_;
136
137  DISALLOW_COPY_AND_ASSIGN(TiledLayer);
138};
139
140}  // namespace cc
141
142#endif  // CC_LAYERS_TILED_LAYER_H_
143