James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 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. |
| 4 | |
| 5 | #ifndef CC_LAYERS_PICTURE_LAYER_IMPL_H_ |
| 6 | #define CC_LAYERS_PICTURE_LAYER_IMPL_H_ |
| 7 | |
| 8 | #include <set> |
| 9 | #include <string> |
| 10 | #include <vector> |
| 11 | |
| 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" |
| 20 | |
| 21 | namespace cc { |
| 22 | |
| 23 | struct AppendQuadsData; |
| 24 | class MicroBenchmarkImpl; |
| 25 | class Tile; |
| 26 | |
| 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(); |
| 35 | |
| 36 | PictureLayerImpl* active; |
| 37 | PictureLayerImpl* pending; |
| 38 | }; |
| 39 | |
| 40 | class CC_EXPORT LayerRasterTileIterator { |
| 41 | public: |
| 42 | LayerRasterTileIterator(); |
| 43 | LayerRasterTileIterator(PictureLayerImpl* layer, bool prioritize_low_res); |
| 44 | ~LayerRasterTileIterator(); |
| 45 | |
| 46 | Tile* operator*(); |
| 47 | const Tile* operator*() const; |
| 48 | LayerRasterTileIterator& operator++(); |
| 49 | operator bool() const; |
| 50 | |
| 51 | private: |
| 52 | enum IteratorType { LOW_RES, HIGH_RES, NUM_ITERATORS }; |
| 53 | |
| 54 | void AdvanceToNextStage(); |
| 55 | |
| 56 | PictureLayerImpl* layer_; |
| 57 | |
| 58 | struct IterationStage { |
| 59 | IteratorType iterator_type; |
| 60 | TilePriority::PriorityBin tile_type; |
| 61 | }; |
| 62 | |
| 63 | size_t current_stage_; |
| 64 | |
| 65 | // One low res stage, and three high res stages. |
| 66 | IterationStage stages_[4]; |
| 67 | PictureLayerTiling::TilingRasterTileIterator iterators_[NUM_ITERATORS]; |
| 68 | }; |
| 69 | |
| 70 | class CC_EXPORT LayerEvictionTileIterator { |
| 71 | public: |
| 72 | LayerEvictionTileIterator(); |
| 73 | LayerEvictionTileIterator(PictureLayerImpl* layer, |
| 74 | TreePriority tree_priority); |
| 75 | ~LayerEvictionTileIterator(); |
| 76 | |
| 77 | Tile* operator*(); |
| 78 | const Tile* operator*() const; |
| 79 | LayerEvictionTileIterator& operator++(); |
| 80 | operator bool() const; |
| 81 | |
| 82 | private: |
| 83 | bool AdvanceToNextCategory(); |
| 84 | bool AdvanceToNextTilingRangeType(); |
| 85 | bool AdvanceToNextTiling(); |
| 86 | |
| 87 | PictureLayerTilingSet::TilingRange CurrentTilingRange() const; |
| 88 | size_t CurrentTilingIndex() const; |
| 89 | |
| 90 | PictureLayerImpl* layer_; |
| 91 | TreePriority tree_priority_; |
| 92 | |
| 93 | PictureLayerTiling::EvictionCategory current_category_; |
| 94 | PictureLayerTilingSet::TilingRangeType current_tiling_range_type_; |
| 95 | size_t current_tiling_; |
| 96 | PictureLayerTiling::TilingEvictionTileIterator current_iterator_; |
| 97 | }; |
| 98 | |
| 99 | static scoped_ptr<PictureLayerImpl> Create(LayerTreeImpl* tree_impl, int id) { |
| 100 | return make_scoped_ptr(new PictureLayerImpl(tree_impl, id)); |
| 101 | } |
James Robinson | e1b30cf | 2014-10-21 12:25:40 -0700 | [diff] [blame] | 102 | ~PictureLayerImpl() override; |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 103 | |
| 104 | // LayerImpl overrides. |
James Robinson | e1b30cf | 2014-10-21 12:25:40 -0700 | [diff] [blame] | 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; |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 118 | |
| 119 | // PictureLayerTilingClient overrides. |
James Robinson | e1b30cf | 2014-10-21 12:25:40 -0700 | [diff] [blame] | 120 | scoped_refptr<Tile> CreateTile(PictureLayerTiling* tiling, |
| 121 | const gfx::Rect& content_rect) override; |
James Robinson | 53b7758 | 2014-10-28 17:00:48 -0700 | [diff] [blame] | 122 | RasterSource* GetRasterSource() override; |
James Robinson | e1b30cf | 2014-10-21 12:25:40 -0700 | [diff] [blame] | 123 | gfx::Size CalculateTileSize(const gfx::Size& content_bounds) const override; |
James Robinson | 53b7758 | 2014-10-28 17:00:48 -0700 | [diff] [blame] | 124 | const Region* GetPendingInvalidation() override; |
| 125 | const PictureLayerTiling* GetPendingOrActiveTwinTiling( |
James Robinson | baf71d3 | 2014-10-08 13:00:20 -0700 | [diff] [blame] | 126 | const PictureLayerTiling* tiling) const override; |
James Robinson | e1b30cf | 2014-10-21 12:25:40 -0700 | [diff] [blame] | 127 | PictureLayerTiling* GetRecycledTwinTiling( |
James Robinson | baf71d3 | 2014-10-08 13:00:20 -0700 | [diff] [blame] | 128 | const PictureLayerTiling* tiling) override; |
James Robinson | e1b30cf | 2014-10-21 12:25:40 -0700 | [diff] [blame] | 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; |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 134 | |
| 135 | // PushPropertiesTo active tree => pending tree. |
| 136 | void SyncTiling(const PictureLayerTiling* tiling); |
| 137 | |
| 138 | // Mask-related functions. |
James Robinson | e1b30cf | 2014-10-21 12:25:40 -0700 | [diff] [blame] | 139 | void GetContentsResourceId(ResourceProvider::ResourceId* resource_id, |
| 140 | gfx::Size* resource_size) const override; |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 141 | |
James Robinson | e1b30cf | 2014-10-21 12:25:40 -0700 | [diff] [blame] | 142 | size_t GPUMemoryUsageInBytes() const override; |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 143 | |
James Robinson | e1b30cf | 2014-10-21 12:25:40 -0700 | [diff] [blame] | 144 | void RunMicroBenchmark(MicroBenchmarkImpl* benchmark) override; |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 145 | |
| 146 | // Functions used by tile manager. |
James Robinson | 53b7758 | 2014-10-28 17:00:48 -0700 | [diff] [blame] | 147 | PictureLayerImpl* GetPendingOrActiveTwinLayer() const; |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 148 | bool IsOnActiveOrPendingTree() const; |
| 149 | // Virtual for testing. |
| 150 | virtual bool HasValidTilePriorities() const; |
| 151 | bool AllTilesRequiredForActivationAreReadyToDraw() const; |
| 152 | |
| 153 | protected: |
| 154 | friend class LayerRasterTileIterator; |
| 155 | |
| 156 | PictureLayerImpl(LayerTreeImpl* tree_impl, int id); |
| 157 | PictureLayerTiling* AddTiling(float contents_scale); |
| 158 | void RemoveTiling(float contents_scale); |
| 159 | void RemoveAllTilings(); |
| 160 | void SyncFromActiveLayer(const PictureLayerImpl* other); |
| 161 | void AddTilingsForRasterScale(); |
| 162 | void UpdateTilePriorities(const Occlusion& occlusion_in_content_space); |
| 163 | virtual bool ShouldAdjustRasterScale() const; |
| 164 | virtual void RecalculateRasterScales(); |
| 165 | void CleanUpTilingsOnActiveLayer( |
| 166 | std::vector<PictureLayerTiling*> used_tilings); |
| 167 | float MinimumContentsScale() const; |
| 168 | float SnappedContentsScale(float new_contents_scale); |
| 169 | void ResetRasterScale(); |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 170 | gfx::Rect GetViewportForTilePriorityInContentSpace() const; |
James Robinson | 53b7758 | 2014-10-28 17:00:48 -0700 | [diff] [blame] | 171 | PictureLayerImpl* GetRecycledTwinLayer() const; |
James Robinson | 7f48021 | 2014-10-31 10:28:08 -0700 | [diff] [blame] | 172 | void UpdatePile(scoped_refptr<PicturePileImpl> pile); |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 173 | |
| 174 | void DoPostCommitInitializationIfNeeded() { |
| 175 | if (needs_post_commit_initialization_) |
| 176 | DoPostCommitInitialization(); |
| 177 | } |
| 178 | void DoPostCommitInitialization(); |
| 179 | |
| 180 | bool CanHaveTilings() const; |
| 181 | bool CanHaveTilingWithScale(float contents_scale) const; |
| 182 | void SanityCheckTilingState() const; |
| 183 | |
| 184 | bool ShouldAdjustRasterScaleDuringScaleAnimations() const; |
| 185 | |
James Robinson | e1b30cf | 2014-10-21 12:25:40 -0700 | [diff] [blame] | 186 | void GetDebugBorderProperties(SkColor* color, float* width) const override; |
| 187 | void GetAllTilesForTracing(std::set<const Tile*>* tiles) const override; |
| 188 | void AsValueInto(base::debug::TracedValue* dict) const override; |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 189 | |
| 190 | virtual void UpdateIdealScales(); |
| 191 | float MaximumTilingContentsScale() const; |
| 192 | |
| 193 | PictureLayerImpl* twin_layer_; |
| 194 | |
| 195 | scoped_ptr<PictureLayerTilingSet> tilings_; |
| 196 | scoped_refptr<PicturePileImpl> pile_; |
| 197 | Region invalidation_; |
| 198 | |
| 199 | float ideal_page_scale_; |
| 200 | float ideal_device_scale_; |
| 201 | float ideal_source_scale_; |
| 202 | float ideal_contents_scale_; |
| 203 | |
| 204 | float raster_page_scale_; |
| 205 | float raster_device_scale_; |
| 206 | float raster_source_scale_; |
| 207 | float raster_contents_scale_; |
| 208 | float low_res_raster_contents_scale_; |
| 209 | |
| 210 | bool raster_source_scale_is_fixed_; |
| 211 | bool was_screen_space_transform_animating_; |
| 212 | bool needs_post_commit_initialization_; |
| 213 | // A sanity state check to make sure UpdateTilePriorities only gets called |
| 214 | // after a CalculateContentsScale/ManageTilings. |
| 215 | bool should_update_tile_priorities_; |
James Robinson | e2ac7e8 | 2014-10-15 13:21:59 -0700 | [diff] [blame] | 216 | bool only_used_low_res_last_append_quads_; |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 217 | |
James Robinson | baf71d3 | 2014-10-08 13:00:20 -0700 | [diff] [blame] | 218 | // Any draw properties derived from |transform|, |viewport|, and |clip| |
| 219 | // parameters in LayerTreeHostImpl::SetExternalDrawConstraints are not valid |
| 220 | // for prioritizing tiles during resourceless software draws. This is because |
| 221 | // resourceless software draws can have wildly different transforms/viewports |
| 222 | // from regular draws. Save a copy of the required draw properties of the last |
| 223 | // frame that has a valid viewport for prioritizing tiles. |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 224 | gfx::Rect visible_rect_for_tile_priority_; |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 225 | |
| 226 | friend class PictureLayer; |
| 227 | DISALLOW_COPY_AND_ASSIGN(PictureLayerImpl); |
| 228 | }; |
| 229 | |
| 230 | } // namespace cc |
| 231 | |
| 232 | #endif // CC_LAYERS_PICTURE_LAYER_IMPL_H_ |