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_
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"
24 struct AppendQuadsData
;
25 class MicroBenchmarkImpl
;
28 class CC_EXPORT PictureLayerImpl
30 NON_EXPORTED_BASE(public PictureLayerTilingClient
) {
32 struct CC_EXPORT Pair
{
34 Pair(PictureLayerImpl
* active_layer
, PictureLayerImpl
* pending_layer
);
37 PictureLayerImpl
* active
;
38 PictureLayerImpl
* pending
;
41 static scoped_ptr
<PictureLayerImpl
> Create(
42 LayerTreeImpl
* tree_impl
,
45 scoped_refptr
<SyncedScrollOffset
> scroll_offset
) {
46 return make_scoped_ptr(
47 new PictureLayerImpl(tree_impl
, id
, is_mask
, scroll_offset
));
49 ~PictureLayerImpl() override
;
51 bool is_mask() const { return is_mask_
; }
53 // LayerImpl overrides.
54 const char* LayerTypeAsString() const override
;
55 scoped_ptr
<LayerImpl
> CreateLayerImpl(LayerTreeImpl
* tree_impl
) override
;
56 void PushPropertiesTo(LayerImpl
* layer
) override
;
57 void AppendQuads(RenderPass
* render_pass
,
58 AppendQuadsData
* append_quads_data
) override
;
59 void NotifyTileStateChanged(const Tile
* tile
) override
;
60 void DidBeginTracing() override
;
61 void ReleaseResources() override
;
62 void RecreateResources() override
;
63 skia::RefPtr
<SkPicture
> GetPicture() override
;
65 // PictureLayerTilingClient overrides.
66 scoped_refptr
<Tile
> CreateTile(float contents_scale
,
67 const gfx::Rect
& content_rect
) override
;
68 gfx::Size
CalculateTileSize(const gfx::Size
& content_bounds
) const override
;
69 const Region
* GetPendingInvalidation() override
;
70 const PictureLayerTiling
* GetPendingOrActiveTwinTiling(
71 const PictureLayerTiling
* tiling
) const override
;
72 PictureLayerTiling
* GetRecycledTwinTiling(
73 const PictureLayerTiling
* tiling
) override
;
74 TilePriority::PriorityBin
GetMaxTilePriorityBin() const override
;
75 WhichTree
GetTree() const override
;
76 bool RequiresHighResToDraw() const override
;
78 void UpdateRasterSource(scoped_refptr
<RasterSource
> raster_source
,
79 Region
* new_invalidation
,
80 const PictureLayerTilingSet
* pending_set
);
81 bool UpdateTiles(bool resourceless_software_draw
);
82 void UpdateCanUseLCDTextAfterCommit();
83 bool RasterSourceUsesLCDText() const;
85 // Mask-related functions.
86 void GetContentsResourceId(ResourceProvider::ResourceId
* resource_id
,
87 gfx::Size
* resource_size
) const override
;
89 void SetNearestNeighbor(bool nearest_neighbor
);
91 size_t GPUMemoryUsageInBytes() const override
;
93 void RunMicroBenchmark(MicroBenchmarkImpl
* benchmark
) override
;
95 bool CanHaveTilings() const;
97 PictureLayerTilingSet
* picture_layer_tiling_set() { return tilings_
.get(); }
99 // Functions used by tile manager.
100 PictureLayerImpl
* GetPendingOrActiveTwinLayer() const;
101 bool IsOnActiveOrPendingTree() const;
102 // Virtual for testing.
103 virtual bool HasValidTilePriorities() const;
105 // Used for benchmarking
106 RasterSource
* GetRasterSource() const { return raster_source_
.get(); }
109 friend class LayerRasterTileIterator
;
110 using TileRequirementCheck
= bool (PictureLayerTiling::*)(const Tile
*) const;
112 PictureLayerImpl(LayerTreeImpl
* tree_impl
,
115 scoped_refptr
<SyncedScrollOffset
> scroll_offset
);
116 PictureLayerTiling
* AddTiling(float contents_scale
);
117 void RemoveAllTilings();
118 void AddTilingsForRasterScale();
119 virtual bool ShouldAdjustRasterScale() const;
120 virtual void RecalculateRasterScales();
121 void CleanUpTilingsOnActiveLayer(
122 const std::vector
<PictureLayerTiling
*>& used_tilings
);
123 float MinimumContentsScale() const;
124 float MaximumContentsScale() const;
125 void ResetRasterScale();
126 void UpdateViewportRectForTilePriorityInContentSpace();
127 PictureLayerImpl
* GetRecycledTwinLayer() const;
129 void SanityCheckTilingState() const;
130 bool ShouldAdjustRasterScaleDuringScaleAnimations() const;
132 void GetDebugBorderProperties(SkColor
* color
, float* width
) const override
;
133 void GetAllTilesForTracing(std::set
<const Tile
*>* tiles
) const override
;
134 void AsValueInto(base::trace_event::TracedValue
* dict
) const override
;
136 virtual void UpdateIdealScales();
137 float MaximumTilingContentsScale() const;
138 scoped_ptr
<PictureLayerTilingSet
> CreatePictureLayerTilingSet();
140 PictureLayerImpl
* twin_layer_
;
142 scoped_ptr
<PictureLayerTilingSet
> tilings_
;
143 scoped_refptr
<RasterSource
> raster_source_
;
144 Region invalidation_
;
146 float ideal_page_scale_
;
147 float ideal_device_scale_
;
148 float ideal_source_scale_
;
149 float ideal_contents_scale_
;
151 float raster_page_scale_
;
152 float raster_device_scale_
;
153 float raster_source_scale_
;
154 float raster_contents_scale_
;
155 float low_res_raster_contents_scale_
;
157 bool raster_source_scale_is_fixed_
;
158 bool was_screen_space_transform_animating_
;
159 bool only_used_low_res_last_append_quads_
;
162 bool nearest_neighbor_
;
164 // Any draw properties derived from |transform|, |viewport|, and |clip|
165 // parameters in LayerTreeHostImpl::SetExternalDrawConstraints are not valid
166 // for prioritizing tiles during resourceless software draws. This is because
167 // resourceless software draws can have wildly different transforms/viewports
168 // from regular draws. Save a copy of the required draw properties of the last
169 // frame that has a valid viewport for prioritizing tiles.
170 gfx::Rect visible_rect_for_tile_priority_
;
171 gfx::Rect viewport_rect_for_tile_priority_in_content_space_
;
173 // List of tilings that were used last time we appended quads. This can be
174 // used as an optimization not to remove tilings if they are still being
175 // drawn. Note that accessing this vector should only be done in the context
176 // of comparing pointers, since objects pointed to are not guaranteed to
178 std::vector
<PictureLayerTiling
*> last_append_quads_tilings_
;
180 DISALLOW_COPY_AND_ASSIGN(PictureLayerImpl
);
185 #endif // CC_LAYERS_PICTURE_LAYER_IMPL_H_