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/playback/picture_pile_impl.h"
16 #include "cc/tiles/picture_layer_tiling.h"
17 #include "cc/tiles/picture_layer_tiling_set.h"
18 #include "cc/tiles/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 static scoped_ptr
<PictureLayerImpl
> Create(
33 LayerTreeImpl
* tree_impl
,
36 scoped_refptr
<SyncedScrollOffset
> scroll_offset
) {
37 return make_scoped_ptr(
38 new PictureLayerImpl(tree_impl
, id
, is_mask
, scroll_offset
));
40 ~PictureLayerImpl() override
;
42 bool is_mask() const { return is_mask_
; }
44 // LayerImpl overrides.
45 const char* LayerTypeAsString() const override
;
46 scoped_ptr
<LayerImpl
> CreateLayerImpl(LayerTreeImpl
* tree_impl
) override
;
47 void PushPropertiesTo(LayerImpl
* layer
) override
;
48 void AppendQuads(RenderPass
* render_pass
,
49 AppendQuadsData
* append_quads_data
) override
;
50 void NotifyTileStateChanged(const Tile
* tile
) override
;
51 void DidBeginTracing() override
;
52 void ReleaseResources() override
;
53 void RecreateResources() override
;
54 skia::RefPtr
<SkPicture
> GetPicture() override
;
55 Region
GetInvalidationRegion() override
;
57 // PictureLayerTilingClient overrides.
58 ScopedTilePtr
CreateTile(const Tile::CreateInfo
& info
) override
;
59 gfx::Size
CalculateTileSize(const gfx::Size
& content_bounds
) const override
;
60 const Region
* GetPendingInvalidation() override
;
61 const PictureLayerTiling
* GetPendingOrActiveTwinTiling(
62 const PictureLayerTiling
* tiling
) const override
;
63 bool HasValidTilePriorities() const override
;
64 bool RequiresHighResToDraw() const override
;
65 gfx::Rect
GetEnclosingRectInTargetSpace() const override
;
67 void set_gpu_raster_max_texture_size(gfx::Size gpu_raster_max_texture_size
) {
68 gpu_raster_max_texture_size_
= gpu_raster_max_texture_size
;
70 void UpdateRasterSource(scoped_refptr
<RasterSource
> raster_source
,
71 Region
* new_invalidation
,
72 const PictureLayerTilingSet
* pending_set
);
73 bool UpdateTiles(bool resourceless_software_draw
);
74 void UpdateCanUseLCDTextAfterCommit();
75 bool RasterSourceUsesLCDText() const;
76 WhichTree
GetTree() const;
78 // Mask-related functions.
79 void GetContentsResourceId(ResourceId
* resource_id
,
80 gfx::Size
* resource_size
) const override
;
82 void SetNearestNeighbor(bool nearest_neighbor
);
84 size_t GPUMemoryUsageInBytes() const override
;
86 void RunMicroBenchmark(MicroBenchmarkImpl
* benchmark
) override
;
88 bool CanHaveTilings() const;
90 PictureLayerTilingSet
* picture_layer_tiling_set() { return tilings_
.get(); }
92 // Functions used by tile manager.
93 PictureLayerImpl
* GetPendingOrActiveTwinLayer() const;
94 bool IsOnActiveOrPendingTree() const;
96 // Used for benchmarking
97 RasterSource
* GetRasterSource() const { return raster_source_
.get(); }
100 friend class LayerRasterTileIterator
;
101 using TileRequirementCheck
= bool (PictureLayerTiling::*)(const Tile
*) const;
103 PictureLayerImpl(LayerTreeImpl
* tree_impl
,
106 scoped_refptr
<SyncedScrollOffset
> scroll_offset
);
107 PictureLayerTiling
* AddTiling(float contents_scale
);
108 void RemoveAllTilings();
109 void AddTilingsForRasterScale();
110 void AddLowResolutionTilingIfNeeded();
111 virtual bool ShouldAdjustRasterScale() const;
112 virtual void RecalculateRasterScales();
113 void CleanUpTilingsOnActiveLayer(
114 const std::vector
<PictureLayerTiling
*>& used_tilings
);
115 float MinimumContentsScale() const;
116 float MaximumContentsScale() const;
117 void ResetRasterScale();
118 void UpdateViewportRectForTilePriorityInContentSpace();
119 PictureLayerImpl
* GetRecycledTwinLayer() const;
121 void SanityCheckTilingState() const;
122 bool ShouldAdjustRasterScaleDuringScaleAnimations() const;
124 void GetDebugBorderProperties(SkColor
* color
, float* width
) const override
;
125 void GetAllPrioritizedTilesForTracing(
126 std::vector
<PrioritizedTile
>* prioritized_tiles
) const override
;
127 void AsValueInto(base::trace_event::TracedValue
* dict
) const override
;
129 virtual void UpdateIdealScales();
130 float MaximumTilingContentsScale() const;
131 scoped_ptr
<PictureLayerTilingSet
> CreatePictureLayerTilingSet();
133 PictureLayerImpl
* twin_layer_
;
135 scoped_ptr
<PictureLayerTilingSet
> tilings_
;
136 scoped_refptr
<RasterSource
> raster_source_
;
137 Region invalidation_
;
139 float ideal_page_scale_
;
140 float ideal_device_scale_
;
141 float ideal_source_scale_
;
142 float ideal_contents_scale_
;
144 float raster_page_scale_
;
145 float raster_device_scale_
;
146 float raster_source_scale_
;
147 float raster_contents_scale_
;
148 float low_res_raster_contents_scale_
;
150 bool raster_source_scale_is_fixed_
;
151 bool was_screen_space_transform_animating_
;
152 bool only_used_low_res_last_append_quads_
;
155 bool nearest_neighbor_
;
157 // Any draw properties derived from |transform|, |viewport|, and |clip|
158 // parameters in LayerTreeHostImpl::SetExternalDrawConstraints are not valid
159 // for prioritizing tiles during resourceless software draws. This is because
160 // resourceless software draws can have wildly different transforms/viewports
161 // from regular draws. Save a copy of the required draw properties of the last
162 // frame that has a valid viewport for prioritizing tiles.
163 gfx::Rect visible_rect_for_tile_priority_
;
164 gfx::Rect viewport_rect_for_tile_priority_in_content_space_
;
166 gfx::Size gpu_raster_max_texture_size_
;
168 // List of tilings that were used last time we appended quads. This can be
169 // used as an optimization not to remove tilings if they are still being
170 // drawn. Note that accessing this vector should only be done in the context
171 // of comparing pointers, since objects pointed to are not guaranteed to
173 std::vector
<PictureLayerTiling
*> last_append_quads_tilings_
;
175 DISALLOW_COPY_AND_ASSIGN(PictureLayerImpl
);
180 #endif // CC_LAYERS_PICTURE_LAYER_IMPL_H_