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(float contents_scale
,
59 const gfx::Rect
& content_rect
) override
;
60 gfx::Size
CalculateTileSize(const gfx::Size
& content_bounds
) const override
;
61 const Region
* GetPendingInvalidation() override
;
62 const PictureLayerTiling
* GetPendingOrActiveTwinTiling(
63 const PictureLayerTiling
* tiling
) const override
;
64 bool HasValidTilePriorities() const override
;
65 bool RequiresHighResToDraw() const override
;
66 gfx::Rect
GetEnclosingRectInTargetSpace() const override
;
68 void set_gpu_raster_max_texture_size(gfx::Size gpu_raster_max_texture_size
) {
69 gpu_raster_max_texture_size_
= gpu_raster_max_texture_size
;
71 void UpdateRasterSource(scoped_refptr
<RasterSource
> raster_source
,
72 Region
* new_invalidation
,
73 const PictureLayerTilingSet
* pending_set
);
74 bool UpdateTiles(bool resourceless_software_draw
);
75 void UpdateCanUseLCDTextAfterCommit();
76 bool RasterSourceUsesLCDText() const;
77 WhichTree
GetTree() const;
79 // Mask-related functions.
80 void GetContentsResourceId(ResourceId
* resource_id
,
81 gfx::Size
* resource_size
) const override
;
83 void SetNearestNeighbor(bool nearest_neighbor
);
85 size_t GPUMemoryUsageInBytes() const override
;
87 void RunMicroBenchmark(MicroBenchmarkImpl
* benchmark
) override
;
89 bool CanHaveTilings() const;
91 PictureLayerTilingSet
* picture_layer_tiling_set() { return tilings_
.get(); }
93 // Functions used by tile manager.
94 PictureLayerImpl
* GetPendingOrActiveTwinLayer() const;
95 bool IsOnActiveOrPendingTree() const;
97 // Used for benchmarking
98 RasterSource
* GetRasterSource() const { return raster_source_
.get(); }
101 friend class LayerRasterTileIterator
;
102 using TileRequirementCheck
= bool (PictureLayerTiling::*)(const Tile
*) const;
104 PictureLayerImpl(LayerTreeImpl
* tree_impl
,
107 scoped_refptr
<SyncedScrollOffset
> scroll_offset
);
108 PictureLayerTiling
* AddTiling(float contents_scale
);
109 void RemoveAllTilings();
110 void AddTilingsForRasterScale();
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_