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 void AddLowResolutionTilingIfNeeded();
112 virtual bool ShouldAdjustRasterScale() const;
113 virtual void RecalculateRasterScales();
114 void CleanUpTilingsOnActiveLayer(
115 const std::vector
<PictureLayerTiling
*>& used_tilings
);
116 float MinimumContentsScale() const;
117 float MaximumContentsScale() const;
118 void ResetRasterScale();
119 void UpdateViewportRectForTilePriorityInContentSpace();
120 PictureLayerImpl
* GetRecycledTwinLayer() const;
122 void SanityCheckTilingState() const;
123 bool ShouldAdjustRasterScaleDuringScaleAnimations() const;
125 void GetDebugBorderProperties(SkColor
* color
, float* width
) const override
;
126 void GetAllPrioritizedTilesForTracing(
127 std::vector
<PrioritizedTile
>* prioritized_tiles
) const override
;
128 void AsValueInto(base::trace_event::TracedValue
* dict
) const override
;
130 virtual void UpdateIdealScales();
131 float MaximumTilingContentsScale() const;
132 scoped_ptr
<PictureLayerTilingSet
> CreatePictureLayerTilingSet();
134 PictureLayerImpl
* twin_layer_
;
136 scoped_ptr
<PictureLayerTilingSet
> tilings_
;
137 scoped_refptr
<RasterSource
> raster_source_
;
138 Region invalidation_
;
140 float ideal_page_scale_
;
141 float ideal_device_scale_
;
142 float ideal_source_scale_
;
143 float ideal_contents_scale_
;
145 float raster_page_scale_
;
146 float raster_device_scale_
;
147 float raster_source_scale_
;
148 float raster_contents_scale_
;
149 float low_res_raster_contents_scale_
;
151 bool raster_source_scale_is_fixed_
;
152 bool was_screen_space_transform_animating_
;
153 bool only_used_low_res_last_append_quads_
;
156 bool nearest_neighbor_
;
158 // Any draw properties derived from |transform|, |viewport|, and |clip|
159 // parameters in LayerTreeHostImpl::SetExternalDrawConstraints are not valid
160 // for prioritizing tiles during resourceless software draws. This is because
161 // resourceless software draws can have wildly different transforms/viewports
162 // from regular draws. Save a copy of the required draw properties of the last
163 // frame that has a valid viewport for prioritizing tiles.
164 gfx::Rect visible_rect_for_tile_priority_
;
165 gfx::Rect viewport_rect_for_tile_priority_in_content_space_
;
167 gfx::Size gpu_raster_max_texture_size_
;
169 // List of tilings that were used last time we appended quads. This can be
170 // used as an optimization not to remove tilings if they are still being
171 // drawn. Note that accessing this vector should only be done in the context
172 // of comparing pointers, since objects pointed to are not guaranteed to
174 std::vector
<PictureLayerTiling
*> last_append_quads_tilings_
;
176 DISALLOW_COPY_AND_ASSIGN(PictureLayerImpl
);
181 #endif // CC_LAYERS_PICTURE_LAYER_IMPL_H_