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
;
64 Region
GetInvalidationRegion() override
;
66 // PictureLayerTilingClient overrides.
67 scoped_refptr
<Tile
> CreateTile(float contents_scale
,
68 const gfx::Rect
& content_rect
) override
;
69 gfx::Size
CalculateTileSize(const gfx::Size
& content_bounds
) const override
;
70 const Region
* GetPendingInvalidation() override
;
71 const PictureLayerTiling
* GetPendingOrActiveTwinTiling(
72 const PictureLayerTiling
* tiling
) const override
;
73 PictureLayerTiling
* GetRecycledTwinTiling(
74 const PictureLayerTiling
* tiling
) override
;
75 TilePriority::PriorityBin
GetMaxTilePriorityBin() const override
;
76 WhichTree
GetTree() const override
;
77 bool RequiresHighResToDraw() const override
;
78 gfx::Rect
GetEnclosingRectInTargetSpace() const override
;
80 void set_gpu_raster_max_texture_size(gfx::Size gpu_raster_max_texture_size
) {
81 gpu_raster_max_texture_size_
= gpu_raster_max_texture_size
;
83 void UpdateRasterSource(scoped_refptr
<RasterSource
> raster_source
,
84 Region
* new_invalidation
,
85 const PictureLayerTilingSet
* pending_set
);
86 bool UpdateTiles(bool resourceless_software_draw
);
87 void UpdateCanUseLCDTextAfterCommit();
88 bool RasterSourceUsesLCDText() const;
90 // Mask-related functions.
91 void GetContentsResourceId(ResourceProvider::ResourceId
* resource_id
,
92 gfx::Size
* resource_size
) const override
;
94 void SetNearestNeighbor(bool nearest_neighbor
);
96 size_t GPUMemoryUsageInBytes() const override
;
98 void RunMicroBenchmark(MicroBenchmarkImpl
* benchmark
) override
;
100 bool CanHaveTilings() const;
102 PictureLayerTilingSet
* picture_layer_tiling_set() { return tilings_
.get(); }
104 // Functions used by tile manager.
105 PictureLayerImpl
* GetPendingOrActiveTwinLayer() const;
106 bool IsOnActiveOrPendingTree() const;
107 // Virtual for testing.
108 virtual bool HasValidTilePriorities() const;
110 // Used for benchmarking
111 RasterSource
* GetRasterSource() const { return raster_source_
.get(); }
114 friend class LayerRasterTileIterator
;
115 using TileRequirementCheck
= bool (PictureLayerTiling::*)(const Tile
*) const;
117 PictureLayerImpl(LayerTreeImpl
* tree_impl
,
120 scoped_refptr
<SyncedScrollOffset
> scroll_offset
);
121 PictureLayerTiling
* AddTiling(float contents_scale
);
122 void RemoveAllTilings();
123 void AddTilingsForRasterScale();
124 virtual bool ShouldAdjustRasterScale() const;
125 virtual void RecalculateRasterScales();
126 void CleanUpTilingsOnActiveLayer(
127 const std::vector
<PictureLayerTiling
*>& used_tilings
);
128 float MinimumContentsScale() const;
129 float MaximumContentsScale() const;
130 void ResetRasterScale();
131 void UpdateViewportRectForTilePriorityInContentSpace();
132 PictureLayerImpl
* GetRecycledTwinLayer() const;
134 void SanityCheckTilingState() const;
135 bool ShouldAdjustRasterScaleDuringScaleAnimations() const;
137 void GetDebugBorderProperties(SkColor
* color
, float* width
) const override
;
138 void GetAllTilesAndPrioritiesForTracing(
139 std::map
<const Tile
*, TilePriority
>* tile_map
) const override
;
140 void AsValueInto(base::trace_event::TracedValue
* dict
) const override
;
142 virtual void UpdateIdealScales();
143 float MaximumTilingContentsScale() const;
144 scoped_ptr
<PictureLayerTilingSet
> CreatePictureLayerTilingSet();
146 PictureLayerImpl
* twin_layer_
;
148 scoped_ptr
<PictureLayerTilingSet
> tilings_
;
149 scoped_refptr
<RasterSource
> raster_source_
;
150 Region invalidation_
;
152 float ideal_page_scale_
;
153 float ideal_device_scale_
;
154 float ideal_source_scale_
;
155 float ideal_contents_scale_
;
157 float raster_page_scale_
;
158 float raster_device_scale_
;
159 float raster_source_scale_
;
160 float raster_contents_scale_
;
161 float low_res_raster_contents_scale_
;
163 bool raster_source_scale_is_fixed_
;
164 bool was_screen_space_transform_animating_
;
165 bool only_used_low_res_last_append_quads_
;
168 bool nearest_neighbor_
;
170 // Any draw properties derived from |transform|, |viewport|, and |clip|
171 // parameters in LayerTreeHostImpl::SetExternalDrawConstraints are not valid
172 // for prioritizing tiles during resourceless software draws. This is because
173 // resourceless software draws can have wildly different transforms/viewports
174 // from regular draws. Save a copy of the required draw properties of the last
175 // frame that has a valid viewport for prioritizing tiles.
176 gfx::Rect visible_rect_for_tile_priority_
;
177 gfx::Rect viewport_rect_for_tile_priority_in_content_space_
;
179 gfx::Size gpu_raster_max_texture_size_
;
181 // List of tilings that were used last time we appended quads. This can be
182 // used as an optimization not to remove tilings if they are still being
183 // drawn. Note that accessing this vector should only be done in the context
184 // of comparing pointers, since objects pointed to are not guaranteed to
186 std::vector
<PictureLayerTiling
*> last_append_quads_tilings_
;
188 DISALLOW_COPY_AND_ASSIGN(PictureLayerImpl
);
193 #endif // CC_LAYERS_PICTURE_LAYER_IMPL_H_