tiled_layer.h revision 03b57e008b61dfcb1fbad3aea950ae0e001748b0
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#include "cc/resources/resource_format.h"
12
13namespace cc {
14class LayerUpdater;
15class PrioritizedResourceManager;
16class PrioritizedResource;
17class UpdatableTile;
18
19class CC_EXPORT TiledLayer : public ContentsScalingLayer {
20 public:
21  enum TilingOption {
22    ALWAYS_TILE,
23    NEVER_TILE,
24    AUTO_TILE,
25  };
26
27  // Layer implementation.
28  virtual void SetIsMask(bool is_mask) OVERRIDE;
29  virtual void PushPropertiesTo(LayerImpl* layer) OVERRIDE;
30  virtual void ReduceMemoryUsage() OVERRIDE;
31  virtual void SetNeedsDisplayRect(const gfx::RectF& dirty_rect) OVERRIDE;
32  virtual void SetLayerTreeHost(LayerTreeHost* layer_tree_host) OVERRIDE;
33  virtual void SetTexturePriorities(const PriorityCalculator& priority_calc)
34      OVERRIDE;
35  virtual SimpleEnclosedRegion VisibleContentOpaqueRegion() const OVERRIDE;
36  virtual bool Update(ResourceUpdateQueue* queue,
37                      const OcclusionTracker<Layer>* occlusion) OVERRIDE;
38  virtual void OnOutputSurfaceCreated() 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(const gfx::Size& size);
49  void SetTextureFormat(ResourceFormat 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(const 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 bool HasDrawableContent() const OVERRIDE;
71
72  // Virtual for testing
73  virtual PrioritizedResourceManager* ResourceManager();
74  const LayerTilingData* TilerForTesting() const { return tiler_.get(); }
75  const PrioritizedResource* ResourceAtForTesting(int i, int j) const;
76
77 private:
78  virtual scoped_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl)
79      OVERRIDE;
80
81  void CreateTilerIfNeeded();
82  void set_tiling_option(TilingOption tiling_option) {
83    tiling_option_ = tiling_option;
84  }
85
86  bool TileOnlyNeedsPartialUpdate(UpdatableTile* tile);
87  bool TileNeedsBufferedUpdate(UpdatableTile* tile);
88
89  void MarkOcclusionsAndRequestTextures(
90      int left,
91      int top,
92      int right,
93      int bottom,
94      const OcclusionTracker<Layer>* occlusion);
95
96  bool UpdateTiles(int left,
97                   int top,
98                   int right,
99                   int bottom,
100                   ResourceUpdateQueue* queue,
101                   const OcclusionTracker<Layer>* occlusion,
102                   bool* did_paint);
103  bool HaveTexturesForTiles(int left,
104                            int top,
105                            int right,
106                            int bottom,
107                            bool ignore_occlusions);
108  void MarkTilesForUpdate(gfx::Rect* update_rect,
109                          gfx::Rect* paint_rect,
110                          int left,
111                          int top,
112                          int right,
113                          int bottom,
114                          bool ignore_occlusions);
115  void UpdateTileTextures(const gfx::Rect& update_rect,
116                          const gfx::Rect& paint_rect,
117                          int left,
118                          int top,
119                          int right,
120                          int bottom,
121                          ResourceUpdateQueue* queue,
122                          const OcclusionTracker<Layer>* occlusion);
123  void UpdateScrollPrediction();
124
125  UpdatableTile* TileAt(int i, int j) const;
126  UpdatableTile* CreateTile(int i, int j);
127
128  bool IsSmallAnimatedLayer() const;
129
130  ResourceFormat texture_format_;
131  bool skips_draw_;
132  bool failed_update_;
133
134  // Used for predictive painting.
135  gfx::Vector2d predicted_scroll_;
136  gfx::Rect predicted_visible_rect_;
137  gfx::Rect previous_visible_rect_;
138  gfx::Size previous_content_bounds_;
139
140  TilingOption tiling_option_;
141  scoped_ptr<LayerTilingData> tiler_;
142
143  DISALLOW_COPY_AND_ASSIGN(TiledLayer);
144};
145
146}  // namespace cc
147
148#endif  // CC_LAYERS_TILED_LAYER_H_
149