Update EnsureProcessGetsReaped to receive a pid.
[chromium-blink-merge.git] / cc / layers / picture_layer_impl.h
blob57947cc0775523a30bb857e99c199c8d0615a4bf
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 "cc/resources/tiling_set_eviction_queue.h"
19 #include "skia/ext/refptr.h"
20 #include "third_party/skia/include/core/SkPicture.h"
22 namespace cc {
24 struct AppendQuadsData;
25 class MicroBenchmarkImpl;
26 class Tile;
28 class CC_EXPORT PictureLayerImpl
29 : public LayerImpl,
30 NON_EXPORTED_BASE(public PictureLayerTilingClient) {
31 public:
32 struct CC_EXPORT Pair {
33 Pair();
34 Pair(PictureLayerImpl* active_layer, PictureLayerImpl* pending_layer);
35 ~Pair();
37 PictureLayerImpl* active;
38 PictureLayerImpl* pending;
41 static scoped_ptr<PictureLayerImpl> Create(LayerTreeImpl* tree_impl,
42 int id,
43 bool is_mask) {
44 return make_scoped_ptr(new PictureLayerImpl(tree_impl, id, is_mask));
46 ~PictureLayerImpl() override;
48 bool is_mask() const { return is_mask_; }
50 // LayerImpl overrides.
51 const char* LayerTypeAsString() const override;
52 scoped_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl) override;
53 void PushPropertiesTo(LayerImpl* layer) override;
54 void AppendQuads(RenderPass* render_pass,
55 const Occlusion& occlusion_in_content_space,
56 AppendQuadsData* append_quads_data) override;
57 bool UpdateTiles(const Occlusion& occlusion_in_content_space,
58 bool resourceless_software_draw) override;
59 void NotifyTileStateChanged(const Tile* tile) override;
60 void DidBeginTracing() override;
61 void ReleaseResources() override;
62 skia::RefPtr<SkPicture> GetPicture() override;
64 // PictureLayerTilingClient overrides.
65 scoped_refptr<Tile> CreateTile(float contents_scale,
66 const gfx::Rect& content_rect) override;
67 gfx::Size CalculateTileSize(const gfx::Size& content_bounds) const override;
68 const Region* GetPendingInvalidation() override;
69 const PictureLayerTiling* GetPendingOrActiveTwinTiling(
70 const PictureLayerTiling* tiling) const override;
71 PictureLayerTiling* GetRecycledTwinTiling(
72 const PictureLayerTiling* tiling) override;
73 TilePriority::PriorityBin GetMaxTilePriorityBin() const override;
74 WhichTree GetTree() const override;
75 bool RequiresHighResToDraw() const override;
77 void UpdateRasterSource(scoped_refptr<RasterSource> raster_source,
78 Region* new_invalidation,
79 const PictureLayerTilingSet* pending_set);
81 // Mask-related functions.
82 void GetContentsResourceId(ResourceProvider::ResourceId* resource_id,
83 gfx::Size* resource_size) const override;
85 void SetNearestNeighbor(bool nearest_neighbor);
87 size_t GPUMemoryUsageInBytes() const override;
89 void RunMicroBenchmark(MicroBenchmarkImpl* benchmark) override;
91 bool CanHaveTilings() const;
93 PictureLayerTilingSet* picture_layer_tiling_set() { return tilings_.get(); }
95 // Functions used by tile manager.
96 PictureLayerImpl* GetPendingOrActiveTwinLayer() const;
97 bool IsOnActiveOrPendingTree() const;
98 // Virtual for testing.
99 virtual bool HasValidTilePriorities() const;
100 bool AllTilesRequiredForActivationAreReadyToDraw() const;
101 bool AllTilesRequiredForDrawAreReadyToDraw() const;
103 // Used for benchmarking
104 RasterSource* GetRasterSource() const { return raster_source_.get(); }
106 protected:
107 friend class LayerRasterTileIterator;
108 using TileRequirementCheck = bool (PictureLayerTiling::*)(const Tile*) const;
110 PictureLayerImpl(LayerTreeImpl* tree_impl, int id, bool is_mask);
111 PictureLayerTiling* AddTiling(float contents_scale);
112 void RemoveAllTilings();
113 void AddTilingsForRasterScale();
114 bool UpdateTilePriorities(const Occlusion& occlusion_in_content_space);
115 virtual bool ShouldAdjustRasterScale() const;
116 virtual void RecalculateRasterScales();
117 void CleanUpTilingsOnActiveLayer(
118 std::vector<PictureLayerTiling*> used_tilings);
119 float MinimumContentsScale() const;
120 float MaximumContentsScale() const;
121 void ResetRasterScale();
122 gfx::Rect GetViewportForTilePriorityInContentSpace() const;
123 PictureLayerImpl* GetRecycledTwinLayer() const;
125 void SanityCheckTilingState() const;
126 // Checks if all tiles required for a certain action (e.g. activation) are
127 // ready to draw. is_tile_required_callback gets called on all candidate
128 // tiles and returns true if the tile is required for the action.
129 bool AllTilesRequiredAreReadyToDraw(
130 TileRequirementCheck is_tile_required_callback) const;
132 bool ShouldAdjustRasterScaleDuringScaleAnimations() const;
134 void GetDebugBorderProperties(SkColor* color, float* width) const override;
135 void GetAllTilesForTracing(std::set<const Tile*>* tiles) const override;
136 void AsValueInto(base::debug::TracedValue* dict) const override;
138 virtual void UpdateIdealScales();
139 float MaximumTilingContentsScale() const;
140 scoped_ptr<PictureLayerTilingSet> CreatePictureLayerTilingSet();
142 PictureLayerImpl* twin_layer_;
144 scoped_ptr<PictureLayerTilingSet> tilings_;
145 scoped_refptr<RasterSource> raster_source_;
146 Region invalidation_;
148 float ideal_page_scale_;
149 float ideal_device_scale_;
150 float ideal_source_scale_;
151 float ideal_contents_scale_;
153 float raster_page_scale_;
154 float raster_device_scale_;
155 float raster_source_scale_;
156 float raster_contents_scale_;
157 float low_res_raster_contents_scale_;
159 bool raster_source_scale_is_fixed_;
160 bool was_screen_space_transform_animating_;
161 // A sanity state check to make sure UpdateTilePriorities only gets called
162 // after a CalculateContentsScale/ManageTilings.
163 bool should_update_tile_priorities_;
164 bool only_used_low_res_last_append_quads_;
165 const bool is_mask_;
167 bool nearest_neighbor_;
169 // Any draw properties derived from |transform|, |viewport|, and |clip|
170 // parameters in LayerTreeHostImpl::SetExternalDrawConstraints are not valid
171 // for prioritizing tiles during resourceless software draws. This is because
172 // resourceless software draws can have wildly different transforms/viewports
173 // from regular draws. Save a copy of the required draw properties of the last
174 // frame that has a valid viewport for prioritizing tiles.
175 gfx::Rect visible_rect_for_tile_priority_;
177 DISALLOW_COPY_AND_ASSIGN(PictureLayerImpl);
180 } // namespace cc
182 #endif // CC_LAYERS_PICTURE_LAYER_IMPL_H_