summaryrefslogtreecommitdiffstats
path: root/cc/layers/picture_layer_impl.h
blob: 1ac106a7c1bce10fe0bddfbc3b5c46d1ae6a1684 (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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
// Copyright 2012 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_PICTURE_LAYER_IMPL_H_
#define CC_LAYERS_PICTURE_LAYER_IMPL_H_

#include <set>
#include <string>
#include <vector>

#include "cc/base/cc_export.h"
#include "cc/base/scoped_ptr_vector.h"
#include "cc/layers/layer_impl.h"
#include "cc/resources/picture_layer_tiling.h"
#include "cc/resources/picture_layer_tiling_set.h"
#include "cc/resources/picture_pile_impl.h"
#include "skia/ext/refptr.h"
#include "third_party/skia/include/core/SkPicture.h"

namespace cc {

struct AppendQuadsData;
class MicroBenchmarkImpl;
class Tile;

class CC_EXPORT PictureLayerImpl
    : public LayerImpl,
      NON_EXPORTED_BASE(public PictureLayerTilingClient) {
 public:
  struct CC_EXPORT Pair {
    Pair();
    Pair(PictureLayerImpl* active_layer, PictureLayerImpl* pending_layer);
    ~Pair();

    PictureLayerImpl* active;
    PictureLayerImpl* pending;
  };

  class CC_EXPORT LayerRasterTileIterator {
   public:
    LayerRasterTileIterator();
    LayerRasterTileIterator(PictureLayerImpl* layer, bool prioritize_low_res);
    ~LayerRasterTileIterator();

    Tile* operator*();
    const Tile* operator*() const;
    LayerRasterTileIterator& operator++();
    operator bool() const;

   private:
    enum IteratorType { LOW_RES, HIGH_RES, NUM_ITERATORS };

    void AdvanceToNextStage();

    PictureLayerImpl* layer_;

    struct IterationStage {
      IteratorType iterator_type;
      TilePriority::PriorityBin tile_type;
    };

    size_t current_stage_;

    // One low res stage, and three high res stages.
    IterationStage stages_[4];
    PictureLayerTiling::TilingRasterTileIterator iterators_[NUM_ITERATORS];
  };

  class CC_EXPORT LayerEvictionTileIterator {
   public:
    LayerEvictionTileIterator();
    LayerEvictionTileIterator(PictureLayerImpl* layer,
                              TreePriority tree_priority);
    ~LayerEvictionTileIterator();

    Tile* operator*();
    const Tile* operator*() const;
    LayerEvictionTileIterator& operator++();
    operator bool() const;

   private:
    bool AdvanceToNextCategory();
    bool AdvanceToNextTilingRangeType();
    bool AdvanceToNextTiling();

    PictureLayerTilingSet::TilingRange CurrentTilingRange() const;
    size_t CurrentTilingIndex() const;

    PictureLayerImpl* layer_;
    TreePriority tree_priority_;

    PictureLayerTiling::EvictionCategory current_category_;
    PictureLayerTilingSet::TilingRangeType current_tiling_range_type_;
    size_t current_tiling_;
    PictureLayerTiling::TilingEvictionTileIterator current_iterator_;
  };

  static scoped_ptr<PictureLayerImpl> Create(LayerTreeImpl* tree_impl, int id) {
    return make_scoped_ptr(new PictureLayerImpl(tree_impl, id));
  }
  ~PictureLayerImpl() override;

  // LayerImpl overrides.
  const char* LayerTypeAsString() const override;
  scoped_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl) override;
  void PushPropertiesTo(LayerImpl* layer) override;
  void AppendQuads(RenderPass* render_pass,
                   const Occlusion& occlusion_in_content_space,
                   AppendQuadsData* append_quads_data) override;
  void UpdateTiles(const Occlusion& occlusion_in_content_space,
                   bool resourceless_software_draw) override;
  void NotifyTileStateChanged(const Tile* tile) override;
  void DidBecomeActive() override;
  void DidBeginTracing() override;
  void ReleaseResources() override;
  skia::RefPtr<SkPicture> GetPicture() override;

  // PictureLayerTilingClient overrides.
  scoped_refptr<Tile> CreateTile(PictureLayerTiling* tiling,
                                 const gfx::Rect& content_rect) override;
  PicturePileImpl* GetPile() override;
  gfx::Size CalculateTileSize(const gfx::Size& content_bounds) const override;
  const Region* GetInvalidation() override;
  const PictureLayerTiling* GetTwinTiling(
      const PictureLayerTiling* tiling) const override;
  PictureLayerTiling* GetRecycledTwinTiling(
      const PictureLayerTiling* tiling) override;
  size_t GetMaxTilesForInterestArea() const override;
  float GetSkewportTargetTimeInSeconds() const override;
  int GetSkewportExtrapolationLimitInContentPixels() const override;
  WhichTree GetTree() const override;
  bool RequiresHighResToDraw() const override;

  // PushPropertiesTo active tree => pending tree.
  void SyncTiling(const PictureLayerTiling* tiling);

  // Mask-related functions.
  void GetContentsResourceId(ResourceProvider::ResourceId* resource_id,
                             gfx::Size* resource_size) const override;

  size_t GPUMemoryUsageInBytes() const override;

  void RunMicroBenchmark(MicroBenchmarkImpl* benchmark) override;

  // Functions used by tile manager.
  PictureLayerImpl* GetTwinLayer() { return twin_layer_; }
  bool IsOnActiveOrPendingTree() const;
  // Virtual for testing.
  virtual bool HasValidTilePriorities() const;
  bool AllTilesRequiredForActivationAreReadyToDraw() const;

 protected:
  friend class LayerRasterTileIterator;

  PictureLayerImpl(LayerTreeImpl* tree_impl, int id);
  PictureLayerTiling* AddTiling(float contents_scale);
  void RemoveTiling(float contents_scale);
  void RemoveAllTilings();
  void SyncFromActiveLayer(const PictureLayerImpl* other);
  void AddTilingsForRasterScale();
  void UpdateTilePriorities(const Occlusion& occlusion_in_content_space);
  virtual bool ShouldAdjustRasterScale() const;
  virtual void RecalculateRasterScales();
  void CleanUpTilingsOnActiveLayer(
      std::vector<PictureLayerTiling*> used_tilings);
  float MinimumContentsScale() const;
  float SnappedContentsScale(float new_contents_scale);
  void ResetRasterScale();
  gfx::Rect GetViewportForTilePriorityInContentSpace() const;
  PictureLayerImpl* GetRecycledTwinLayer();

  void DoPostCommitInitializationIfNeeded() {
    if (needs_post_commit_initialization_)
      DoPostCommitInitialization();
  }
  void DoPostCommitInitialization();

  bool CanHaveTilings() const;
  bool CanHaveTilingWithScale(float contents_scale) const;
  void SanityCheckTilingState() const;

  bool ShouldAdjustRasterScaleDuringScaleAnimations() const;

  void GetDebugBorderProperties(SkColor* color, float* width) const override;
  void GetAllTilesForTracing(std::set<const Tile*>* tiles) const override;
  void AsValueInto(base::debug::TracedValue* dict) const override;

  virtual void UpdateIdealScales();
  float MaximumTilingContentsScale() const;

  PictureLayerImpl* twin_layer_;

  scoped_ptr<PictureLayerTilingSet> tilings_;
  scoped_refptr<PicturePileImpl> pile_;
  Region invalidation_;

  float ideal_page_scale_;
  float ideal_device_scale_;
  float ideal_source_scale_;
  float ideal_contents_scale_;

  float raster_page_scale_;
  float raster_device_scale_;
  float raster_source_scale_;
  float raster_contents_scale_;
  float low_res_raster_contents_scale_;

  bool raster_source_scale_is_fixed_;
  bool was_screen_space_transform_animating_;
  bool needs_post_commit_initialization_;
  // A sanity state check to make sure UpdateTilePriorities only gets called
  // after a CalculateContentsScale/ManageTilings.
  bool should_update_tile_priorities_;
  bool only_used_low_res_last_append_quads_;

  // Any draw properties derived from |transform|, |viewport|, and |clip|
  // parameters in LayerTreeHostImpl::SetExternalDrawConstraints are not valid
  // for prioritizing tiles during resourceless software draws. This is because
  // resourceless software draws can have wildly different transforms/viewports
  // from regular draws. Save a copy of the required draw properties of the last
  // frame that has a valid viewport for prioritizing tiles.
  gfx::Rect visible_rect_for_tile_priority_;

  friend class PictureLayer;
  DISALLOW_COPY_AND_ASSIGN(PictureLayerImpl);
};

}  // namespace cc

#endif  // CC_LAYERS_PICTURE_LAYER_IMPL_H_