Don't invoke Render() upon receipt of pause complete signal.
[chromium-blink-merge.git] / cc / layers / picture_layer_impl.h
blob9a775463d739d79a2cf135d5cc3a18d7a66bee13
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.
5 #ifndef CC_LAYERS_PICTURE_LAYER_IMPL_H_
6 #define CC_LAYERS_PICTURE_LAYER_IMPL_H_
8 #include <set>
9 #include <string>
10 #include <vector>
12 #include "cc/base/cc_export.h"
13 #include "cc/base/scoped_ptr_vector.h"
14 #include "cc/layers/layer_impl.h"
15 #include "cc/resources/picture_layer_tiling.h"
16 #include "cc/resources/picture_layer_tiling_set.h"
17 #include "cc/resources/picture_pile_impl.h"
18 #include "skia/ext/refptr.h"
19 #include "third_party/skia/include/core/SkPicture.h"
21 namespace cc {
23 struct AppendQuadsData;
24 class MicroBenchmarkImpl;
25 class Tile;
27 class CC_EXPORT PictureLayerImpl
28 : public LayerImpl,
29 NON_EXPORTED_BASE(public PictureLayerTilingClient) {
30 public:
31 struct CC_EXPORT Pair {
32 Pair();
33 Pair(PictureLayerImpl* active_layer, PictureLayerImpl* pending_layer);
34 ~Pair();
36 PictureLayerImpl* active;
37 PictureLayerImpl* pending;
40 class CC_EXPORT LayerRasterTileIterator {
41 public:
42 LayerRasterTileIterator();
43 LayerRasterTileIterator(PictureLayerImpl* layer, bool prioritize_low_res);
44 ~LayerRasterTileIterator();
46 Tile* operator*();
47 const Tile* operator*() const;
48 LayerRasterTileIterator& operator++();
49 operator bool() const;
51 private:
52 enum IteratorType { LOW_RES, HIGH_RES, NUM_ITERATORS };
54 void AdvanceToNextStage();
56 PictureLayerImpl* layer_;
58 struct IterationStage {
59 IteratorType iterator_type;
60 TilePriority::PriorityBin tile_type;
63 size_t current_stage_;
65 // One low res stage, and three high res stages.
66 IterationStage stages_[4];
67 PictureLayerTiling::TilingRasterTileIterator iterators_[NUM_ITERATORS];
70 class CC_EXPORT LayerEvictionTileIterator {
71 public:
72 LayerEvictionTileIterator();
73 LayerEvictionTileIterator(PictureLayerImpl* layer,
74 TreePriority tree_priority);
75 ~LayerEvictionTileIterator();
77 Tile* operator*();
78 const Tile* operator*() const;
79 LayerEvictionTileIterator& operator++();
80 operator bool() const;
82 private:
83 bool AdvanceToNextCategory();
84 bool AdvanceToNextTilingRangeType();
85 bool AdvanceToNextTiling();
87 PictureLayerTilingSet::TilingRange CurrentTilingRange() const;
88 size_t CurrentTilingIndex() const;
90 PictureLayerImpl* layer_;
91 TreePriority tree_priority_;
93 PictureLayerTiling::EvictionCategory current_category_;
94 PictureLayerTilingSet::TilingRangeType current_tiling_range_type_;
95 size_t current_tiling_;
96 PictureLayerTiling::TilingEvictionTileIterator current_iterator_;
99 static scoped_ptr<PictureLayerImpl> Create(LayerTreeImpl* tree_impl, int id) {
100 return make_scoped_ptr(new PictureLayerImpl(tree_impl, id));
102 ~PictureLayerImpl() override;
104 // LayerImpl overrides.
105 const char* LayerTypeAsString() const override;
106 scoped_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl) override;
107 void PushPropertiesTo(LayerImpl* layer) override;
108 void AppendQuads(RenderPass* render_pass,
109 const Occlusion& occlusion_in_content_space,
110 AppendQuadsData* append_quads_data) override;
111 void UpdateTiles(const Occlusion& occlusion_in_content_space,
112 bool resourceless_software_draw) override;
113 void NotifyTileStateChanged(const Tile* tile) override;
114 void DidBecomeActive() override;
115 void DidBeginTracing() override;
116 void ReleaseResources() override;
117 skia::RefPtr<SkPicture> GetPicture() override;
119 // PictureLayerTilingClient overrides.
120 scoped_refptr<Tile> CreateTile(PictureLayerTiling* tiling,
121 const gfx::Rect& content_rect) override;
122 gfx::Size CalculateTileSize(const gfx::Size& content_bounds) const override;
123 const Region* GetPendingInvalidation() override;
124 const PictureLayerTiling* GetPendingOrActiveTwinTiling(
125 const PictureLayerTiling* tiling) const override;
126 PictureLayerTiling* GetRecycledTwinTiling(
127 const PictureLayerTiling* tiling) override;
128 TilePriority::PriorityBin GetMaxTilePriorityBin() const override;
129 size_t GetMaxTilesForInterestArea() const override;
130 float GetSkewportTargetTimeInSeconds() const override;
131 int GetSkewportExtrapolationLimitInContentPixels() const override;
132 WhichTree GetTree() const override;
133 bool RequiresHighResToDraw() const override;
135 // PushPropertiesTo active tree => pending tree.
136 void SyncTiling(const PictureLayerTiling* tiling);
138 // Mask-related functions.
139 void GetContentsResourceId(ResourceProvider::ResourceId* resource_id,
140 gfx::Size* resource_size) const override;
141 void set_is_mask(bool is_mask) { is_mask_ = is_mask; }
143 size_t GPUMemoryUsageInBytes() const override;
145 void RunMicroBenchmark(MicroBenchmarkImpl* benchmark) override;
147 bool CanHaveTilings() const;
149 // Functions used by tile manager.
150 PictureLayerImpl* GetPendingOrActiveTwinLayer() const;
151 bool IsOnActiveOrPendingTree() const;
152 // Virtual for testing.
153 virtual bool HasValidTilePriorities() const;
154 bool AllTilesRequiredForActivationAreReadyToDraw() const;
155 bool AllTilesRequiredForDrawAreReadyToDraw() const;
157 protected:
158 friend class LayerRasterTileIterator;
159 using TileRequirementCheck = bool (PictureLayerTiling::*)(const Tile*) const;
161 PictureLayerImpl(LayerTreeImpl* tree_impl, int id);
162 PictureLayerTiling* AddTiling(float contents_scale);
163 void RemoveAllTilings();
164 void SyncFromActiveLayer(const PictureLayerImpl* other);
165 void AddTilingsForRasterScale();
166 void UpdateTilePriorities(const Occlusion& occlusion_in_content_space);
167 virtual bool ShouldAdjustRasterScale() const;
168 virtual void RecalculateRasterScales();
169 void CleanUpTilingsOnActiveLayer(
170 std::vector<PictureLayerTiling*> used_tilings);
171 float MinimumContentsScale() const;
172 void ResetRasterScale();
173 gfx::Rect GetViewportForTilePriorityInContentSpace() const;
174 PictureLayerImpl* GetRecycledTwinLayer() const;
175 void UpdateRasterSource(scoped_refptr<RasterSource> raster_source);
177 void DoPostCommitInitializationIfNeeded() {
178 if (needs_post_commit_initialization_)
179 DoPostCommitInitialization();
181 void DoPostCommitInitialization();
183 bool CanHaveTilingWithScale(float contents_scale) const;
184 void SanityCheckTilingState() const;
185 // Checks if all tiles required for a certain action (e.g. activation) are
186 // ready to draw. is_tile_required_callback gets called on all candidate
187 // tiles and returns true if the tile is required for the action.
188 bool AllTilesRequiredAreReadyToDraw(
189 TileRequirementCheck is_tile_required_callback) const;
191 bool ShouldAdjustRasterScaleDuringScaleAnimations() const;
193 void GetDebugBorderProperties(SkColor* color, float* width) const override;
194 void GetAllTilesForTracing(std::set<const Tile*>* tiles) const override;
195 void AsValueInto(base::debug::TracedValue* dict) const override;
197 virtual void UpdateIdealScales();
198 float MaximumTilingContentsScale() const;
200 PictureLayerImpl* twin_layer_;
202 scoped_ptr<PictureLayerTilingSet> tilings_;
203 scoped_refptr<RasterSource> raster_source_;
204 Region invalidation_;
206 float ideal_page_scale_;
207 float ideal_device_scale_;
208 float ideal_source_scale_;
209 float ideal_contents_scale_;
211 float raster_page_scale_;
212 float raster_device_scale_;
213 float raster_source_scale_;
214 float raster_contents_scale_;
215 float low_res_raster_contents_scale_;
217 bool raster_source_scale_is_fixed_;
218 bool was_screen_space_transform_animating_;
219 bool needs_post_commit_initialization_;
220 // A sanity state check to make sure UpdateTilePriorities only gets called
221 // after a CalculateContentsScale/ManageTilings.
222 bool should_update_tile_priorities_;
223 bool only_used_low_res_last_append_quads_;
224 bool is_mask_;
226 // Any draw properties derived from |transform|, |viewport|, and |clip|
227 // parameters in LayerTreeHostImpl::SetExternalDrawConstraints are not valid
228 // for prioritizing tiles during resourceless software draws. This is because
229 // resourceless software draws can have wildly different transforms/viewports
230 // from regular draws. Save a copy of the required draw properties of the last
231 // frame that has a valid viewport for prioritizing tiles.
232 gfx::Rect visible_rect_for_tile_priority_;
234 friend class PictureLayer;
235 DISALLOW_COPY_AND_ASSIGN(PictureLayerImpl);
238 } // namespace cc
240 #endif // CC_LAYERS_PICTURE_LAYER_IMPL_H_