summaryrefslogtreecommitdiffstats
path: root/cc/layers/tiled_layer.h
blob: d48ebe44082379359d3ef4fbee65c3747ca4cd25 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// Copyright 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CC_LAYERS_TILED_LAYER_H_
#define CC_LAYERS_TILED_LAYER_H_

#include "cc/base/cc_export.h"
#include "cc/layers/contents_scaling_layer.h"
#include "cc/resources/layer_tiling_data.h"
#include "cc/resources/resource_format.h"

namespace cc {
class LayerUpdater;
class PrioritizedResourceManager;
class PrioritizedResource;
class UpdatableTile;

class CC_EXPORT TiledLayer : public ContentsScalingLayer {
 public:
  enum TilingOption {
    ALWAYS_TILE,
    NEVER_TILE,
    AUTO_TILE,
  };

  // Layer implementation.
  void SetIsMask(bool is_mask) override;
  void PushPropertiesTo(LayerImpl* layer) override;
  void ReduceMemoryUsage() override;
  void SetNeedsDisplayRect(const gfx::Rect& dirty_rect) override;
  void SetLayerTreeHost(LayerTreeHost* layer_tree_host) override;
  void SetTexturePriorities(const PriorityCalculator& priority_calc) override;
  SimpleEnclosedRegion VisibleContentOpaqueRegion() const override;
  bool Update(ResourceUpdateQueue* queue,
              const OcclusionTracker<Layer>* occlusion) override;
  void OnOutputSurfaceCreated() override;

 protected:
  TiledLayer();
  ~TiledLayer() override;

  void UpdateTileSizeAndTilingOption();
  void UpdateBounds();

  // Exposed to subclasses for testing.
  void SetTileSize(const gfx::Size& size);
  void SetTextureFormat(ResourceFormat texture_format) {
    texture_format_ = texture_format;
  }
  void SetBorderTexelOption(LayerTilingData::BorderTexelOption option);
  size_t NumPaintedTiles() { return tiler_->tiles().size(); }

  virtual LayerUpdater* Updater() const = 0;
  virtual void CreateUpdaterIfNeeded() = 0;

  // Set invalidations to be potentially repainted during Update().
  void InvalidateContentRect(const gfx::Rect& content_rect);

  // Reset state on tiles that will be used for updating the layer.
  void ResetUpdateState();

  // After preparing an update, returns true if more painting is needed.
  bool NeedsIdlePaint();
  gfx::Rect IdlePaintRect();

  bool SkipsDraw() const { return skips_draw_; }

  bool HasDrawableContent() const override;

  // Virtual for testing
  virtual PrioritizedResourceManager* ResourceManager();
  const LayerTilingData* TilerForTesting() const { return tiler_.get(); }
  const PrioritizedResource* ResourceAtForTesting(int i, int j) const;

 private:
  scoped_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl) override;

  void CreateTilerIfNeeded();
  void set_tiling_option(TilingOption tiling_option) {
    tiling_option_ = tiling_option;
  }

  bool TileOnlyNeedsPartialUpdate(UpdatableTile* tile);
  bool TileNeedsBufferedUpdate(UpdatableTile* tile);

  void MarkOcclusionsAndRequestTextures(
      int left,
      int top,
      int right,
      int bottom,
      const OcclusionTracker<Layer>* occlusion);

  bool UpdateTiles(int left,
                   int top,
                   int right,
                   int bottom,
                   ResourceUpdateQueue* queue,
                   const OcclusionTracker<Layer>* occlusion,
                   bool* did_paint);
  bool HaveTexturesForTiles(int left,
                            int top,
                            int right,
                            int bottom,
                            bool ignore_occlusions);
  void MarkTilesForUpdate(gfx::Rect* update_rect,
                          gfx::Rect* paint_rect,
                          int left,
                          int top,
                          int right,
                          int bottom,
                          bool ignore_occlusions);
  void UpdateTileTextures(const gfx::Rect& update_rect,
                          const gfx::Rect& paint_rect,
                          int left,
                          int top,
                          int right,
                          int bottom,
                          ResourceUpdateQueue* queue,
                          const OcclusionTracker<Layer>* occlusion);
  void UpdateScrollPrediction();

  UpdatableTile* TileAt(int i, int j) const;
  UpdatableTile* CreateTile(int i, int j);

  bool IsSmallAnimatedLayer() const;

  ResourceFormat texture_format_;
  bool skips_draw_;
  bool failed_update_;

  // Used for predictive painting.
  gfx::Vector2d predicted_scroll_;
  gfx::Rect predicted_visible_rect_;
  gfx::Rect previous_visible_rect_;
  gfx::Size previous_content_bounds_;

  TilingOption tiling_option_;
  scoped_ptr<LayerTilingData> tiler_;

  DISALLOW_COPY_AND_ASSIGN(TiledLayer);
};

}  // namespace cc

#endif  // CC_LAYERS_TILED_LAYER_H_