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_
11 #include "cc/base/cc_export.h"
12 #include "cc/base/scoped_ptr_vector.h"
13 #include "cc/layers/layer_impl.h"
14 #include "cc/resources/picture_layer_tiling.h"
15 #include "cc/resources/picture_layer_tiling_set.h"
16 #include "cc/resources/picture_pile_impl.h"
17 #include "skia/ext/refptr.h"
18 #include "third_party/skia/include/core/SkPicture.h"
22 struct AppendQuadsData
;
23 class MicroBenchmarkImpl
;
26 class CC_EXPORT PictureLayerImpl
28 NON_EXPORTED_BASE(public PictureLayerTilingClient
) {
30 class CC_EXPORT LayerRasterTileIterator
{
32 LayerRasterTileIterator();
33 LayerRasterTileIterator(PictureLayerImpl
* layer
, bool prioritize_low_res
);
34 ~LayerRasterTileIterator();
37 LayerRasterTileIterator
& operator++();
38 operator bool() const;
41 enum IteratorType
{ LOW_RES
, HIGH_RES
, NUM_ITERATORS
};
43 PictureLayerImpl
* layer_
;
45 struct IterationStage
{
46 IteratorType iterator_type
;
47 TilePriority::PriorityBin tile_type
;
52 // One low res stage, and three high res stages.
53 IterationStage stages_
[4];
54 PictureLayerTiling::TilingRasterTileIterator iterators_
[NUM_ITERATORS
];
57 class CC_EXPORT LayerEvictionTileIterator
{
59 LayerEvictionTileIterator();
60 LayerEvictionTileIterator(PictureLayerImpl
* layer
,
61 TreePriority tree_priority
);
62 ~LayerEvictionTileIterator();
65 LayerEvictionTileIterator
& operator++();
66 operator bool() const;
69 void AdvanceToNextIterator();
71 PictureLayerTiling::TilingEvictionTileIterator
* it
) const;
73 std::vector
<PictureLayerTiling::TilingEvictionTileIterator
> iterators_
;
74 size_t iterator_index_
;
75 TilePriority::PriorityBin iteration_stage_
;
76 bool required_for_activation_
;
78 PictureLayerImpl
* layer_
;
81 static scoped_ptr
<PictureLayerImpl
> Create(LayerTreeImpl
* tree_impl
, int id
) {
82 return make_scoped_ptr(new PictureLayerImpl(tree_impl
, id
));
84 virtual ~PictureLayerImpl();
86 // LayerImpl overrides.
87 virtual const char* LayerTypeAsString() const OVERRIDE
;
88 virtual scoped_ptr
<LayerImpl
> CreateLayerImpl(LayerTreeImpl
* tree_impl
)
90 virtual void PushPropertiesTo(LayerImpl
* layer
) OVERRIDE
;
91 virtual void AppendQuads(RenderPass
* render_pass
,
92 const OcclusionTracker
<LayerImpl
>& occlusion_tracker
,
93 AppendQuadsData
* append_quads_data
) OVERRIDE
;
94 virtual void UpdateTiles(
95 const OcclusionTracker
<LayerImpl
>* occlusion_tracker
) OVERRIDE
;
96 virtual void NotifyTileStateChanged(const Tile
* tile
) OVERRIDE
;
97 virtual void DidBecomeActive() OVERRIDE
;
98 virtual void DidBeginTracing() OVERRIDE
;
99 virtual void ReleaseResources() OVERRIDE
;
100 virtual skia::RefPtr
<SkPicture
> GetPicture() OVERRIDE
;
102 // PictureLayerTilingClient overrides.
103 virtual scoped_refptr
<Tile
> CreateTile(
104 PictureLayerTiling
* tiling
,
105 const gfx::Rect
& content_rect
) OVERRIDE
;
106 virtual PicturePileImpl
* GetPile() OVERRIDE
;
107 virtual gfx::Size
CalculateTileSize(
108 const gfx::Size
& content_bounds
) const OVERRIDE
;
109 virtual const Region
* GetInvalidation() OVERRIDE
;
110 virtual const PictureLayerTiling
* GetTwinTiling(
111 const PictureLayerTiling
* tiling
) const OVERRIDE
;
112 virtual size_t GetMaxTilesForInterestArea() const OVERRIDE
;
113 virtual float GetSkewportTargetTimeInSeconds() const OVERRIDE
;
114 virtual int GetSkewportExtrapolationLimitInContentPixels() const OVERRIDE
;
116 // PushPropertiesTo active tree => pending tree.
117 void SyncTiling(const PictureLayerTiling
* tiling
);
119 // Mask-related functions
120 void SetIsMask(bool is_mask
);
121 virtual ResourceProvider::ResourceId
ContentsResourceId() const OVERRIDE
;
123 virtual size_t GPUMemoryUsageInBytes() const OVERRIDE
;
125 virtual void RunMicroBenchmark(MicroBenchmarkImpl
* benchmark
) OVERRIDE
;
127 // Functions used by tile manager.
128 PictureLayerImpl
* GetTwinLayer() { return twin_layer_
; }
129 WhichTree
GetTree() const;
130 bool IsOnActiveOrPendingTree() const;
131 bool HasValidTilePriorities() const;
132 bool AllTilesRequiredForActivationAreReadyToDraw() const;
135 friend class LayerRasterTileIterator
;
137 PictureLayerImpl(LayerTreeImpl
* tree_impl
, int id
);
138 PictureLayerTiling
* AddTiling(float contents_scale
);
139 void RemoveTiling(float contents_scale
);
140 void RemoveAllTilings();
141 void SyncFromActiveLayer(const PictureLayerImpl
* other
);
142 void AddTilingsForRasterScale();
143 void UpdateTilePriorities(
144 const OcclusionTracker
<LayerImpl
>* occlusion_tracker
);
145 virtual bool ShouldAdjustRasterScale() const;
146 virtual void RecalculateRasterScales();
147 void CleanUpTilingsOnActiveLayer(
148 std::vector
<PictureLayerTiling
*> used_tilings
);
149 float MinimumContentsScale() const;
150 float SnappedContentsScale(float new_contents_scale
);
151 void ResetRasterScale();
152 void MarkVisibleResourcesAsRequired() const;
153 bool MarkVisibleTilesAsRequired(
154 PictureLayerTiling
* tiling
,
155 const PictureLayerTiling
* optional_twin_tiling
,
156 float contents_scale
,
157 const gfx::Rect
& rect
,
158 const Region
& missing_region
) const;
160 void DoPostCommitInitializationIfNeeded() {
161 if (needs_post_commit_initialization_
)
162 DoPostCommitInitialization();
164 void DoPostCommitInitialization();
166 bool CanHaveTilings() const;
167 bool CanHaveTilingWithScale(float contents_scale
) const;
168 void SanityCheckTilingState() const;
170 virtual void GetDebugBorderProperties(
171 SkColor
* color
, float* width
) const OVERRIDE
;
172 virtual void AsValueInto(base::DictionaryValue
* dict
) const OVERRIDE
;
174 virtual void UpdateIdealScales();
175 float MaximumTilingContentsScale() const;
177 PictureLayerImpl
* twin_layer_
;
179 scoped_ptr
<PictureLayerTilingSet
> tilings_
;
180 scoped_refptr
<PicturePileImpl
> pile_
;
181 Region invalidation_
;
185 float ideal_page_scale_
;
186 float ideal_device_scale_
;
187 float ideal_source_scale_
;
188 float ideal_contents_scale_
;
190 float raster_page_scale_
;
191 float raster_device_scale_
;
192 float raster_source_scale_
;
193 float raster_contents_scale_
;
194 float low_res_raster_contents_scale_
;
196 bool raster_source_scale_is_fixed_
;
197 bool was_screen_space_transform_animating_
;
198 bool needs_post_commit_initialization_
;
199 // A sanity state check to make sure UpdateTilePriorities only gets called
200 // after a CalculateContentsScale/ManageTilings.
201 bool should_update_tile_priorities_
;
203 // Save a copy of the visible rect and viewport size of the last frame that
204 // has a valid viewport for prioritizing tiles.
205 gfx::Rect visible_rect_for_tile_priority_
;
206 gfx::Size viewport_size_for_tile_priority_
;
207 gfx::Transform screen_space_transform_for_tile_priority_
;
209 friend class PictureLayer
;
210 DISALLOW_COPY_AND_ASSIGN(PictureLayerImpl
);
215 #endif // CC_LAYERS_PICTURE_LAYER_IMPL_H_