[Android] Add XXXHDPI assets
[chromium-blink-merge.git] / cc / layers / picture_layer_impl.h
blob2fb877e607a4b22e6a97d372612fbde4c0206598
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 virtual ~PictureLayerImpl();
104 // LayerImpl overrides.
105 virtual const char* LayerTypeAsString() const override;
106 virtual scoped_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl)
107 override;
108 virtual void PushPropertiesTo(LayerImpl* layer) override;
109 virtual void AppendQuads(RenderPass* render_pass,
110 const Occlusion& occlusion_in_content_space,
111 AppendQuadsData* append_quads_data) override;
112 virtual void UpdateTiles(const Occlusion& occlusion_in_content_space,
113 bool resourceless_software_draw) override;
114 virtual void NotifyTileStateChanged(const Tile* tile) override;
115 virtual void DidBecomeActive() override;
116 virtual void DidBeginTracing() override;
117 virtual void ReleaseResources() override;
118 virtual skia::RefPtr<SkPicture> GetPicture() override;
120 // PictureLayerTilingClient overrides.
121 virtual scoped_refptr<Tile> CreateTile(
122 PictureLayerTiling* tiling,
123 const gfx::Rect& content_rect) override;
124 virtual PicturePileImpl* GetPile() override;
125 virtual gfx::Size CalculateTileSize(
126 const gfx::Size& content_bounds) const override;
127 virtual const Region* GetInvalidation() override;
128 virtual const PictureLayerTiling* GetTwinTiling(
129 const PictureLayerTiling* tiling) const override;
130 virtual PictureLayerTiling* GetRecycledTwinTiling(
131 const PictureLayerTiling* tiling) override;
132 virtual size_t GetMaxTilesForInterestArea() const override;
133 virtual float GetSkewportTargetTimeInSeconds() const override;
134 virtual int GetSkewportExtrapolationLimitInContentPixels() const override;
135 virtual WhichTree GetTree() const override;
136 virtual bool RequiresHighResToDraw() const override;
138 // PushPropertiesTo active tree => pending tree.
139 void SyncTiling(const PictureLayerTiling* tiling);
141 // Mask-related functions.
142 virtual ResourceProvider::ResourceId ContentsResourceId() const override;
144 virtual size_t GPUMemoryUsageInBytes() const override;
146 virtual void RunMicroBenchmark(MicroBenchmarkImpl* benchmark) override;
148 // Functions used by tile manager.
149 PictureLayerImpl* GetTwinLayer() { return twin_layer_; }
150 bool IsOnActiveOrPendingTree() const;
151 // Virtual for testing.
152 virtual bool HasValidTilePriorities() const;
153 bool AllTilesRequiredForActivationAreReadyToDraw() const;
155 protected:
156 friend class LayerRasterTileIterator;
158 PictureLayerImpl(LayerTreeImpl* tree_impl, int id);
159 PictureLayerTiling* AddTiling(float contents_scale);
160 void RemoveTiling(float contents_scale);
161 void RemoveAllTilings();
162 void SyncFromActiveLayer(const PictureLayerImpl* other);
163 void AddTilingsForRasterScale();
164 void UpdateTilePriorities(const Occlusion& occlusion_in_content_space);
165 virtual bool ShouldAdjustRasterScale() const;
166 virtual void RecalculateRasterScales();
167 void CleanUpTilingsOnActiveLayer(
168 std::vector<PictureLayerTiling*> used_tilings);
169 float MinimumContentsScale() const;
170 float SnappedContentsScale(float new_contents_scale);
171 void ResetRasterScale();
172 gfx::Rect GetViewportForTilePriorityInContentSpace() const;
173 PictureLayerImpl* GetRecycledTwinLayer();
175 void DoPostCommitInitializationIfNeeded() {
176 if (needs_post_commit_initialization_)
177 DoPostCommitInitialization();
179 void DoPostCommitInitialization();
181 bool CanHaveTilings() const;
182 bool CanHaveTilingWithScale(float contents_scale) const;
183 void SanityCheckTilingState() const;
185 bool ShouldAdjustRasterScaleDuringScaleAnimations() const;
187 virtual void GetDebugBorderProperties(
188 SkColor* color, float* width) const override;
189 virtual void GetAllTilesForTracing(
190 std::set<const Tile*>* tiles) const override;
191 virtual void AsValueInto(base::debug::TracedValue* dict) const override;
193 virtual void UpdateIdealScales();
194 float MaximumTilingContentsScale() const;
196 PictureLayerImpl* twin_layer_;
198 scoped_ptr<PictureLayerTilingSet> tilings_;
199 scoped_refptr<PicturePileImpl> pile_;
200 Region invalidation_;
202 float ideal_page_scale_;
203 float ideal_device_scale_;
204 float ideal_source_scale_;
205 float ideal_contents_scale_;
207 float raster_page_scale_;
208 float raster_device_scale_;
209 float raster_source_scale_;
210 float raster_contents_scale_;
211 float low_res_raster_contents_scale_;
213 bool raster_source_scale_is_fixed_;
214 bool was_screen_space_transform_animating_;
215 bool needs_post_commit_initialization_;
216 // A sanity state check to make sure UpdateTilePriorities only gets called
217 // after a CalculateContentsScale/ManageTilings.
218 bool should_update_tile_priorities_;
219 bool only_used_low_res_last_append_quads_;
221 // Any draw properties derived from |transform|, |viewport|, and |clip|
222 // parameters in LayerTreeHostImpl::SetExternalDrawConstraints are not valid
223 // for prioritizing tiles during resourceless software draws. This is because
224 // resourceless software draws can have wildly different transforms/viewports
225 // from regular draws. Save a copy of the required draw properties of the last
226 // frame that has a valid viewport for prioritizing tiles.
227 gfx::Rect visible_rect_for_tile_priority_;
229 friend class PictureLayer;
230 DISALLOW_COPY_AND_ASSIGN(PictureLayerImpl);
233 } // namespace cc
235 #endif // CC_LAYERS_PICTURE_LAYER_IMPL_H_