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_
11 #include "cc/base/cc_export.h"
12 #include "cc/base/scoped_ptr_vector.h"
13 #include "cc/layers/layer_impl.h"
14 #include "cc/resources/picture_layer_tiling.h"
15 #include "cc/resources/picture_layer_tiling_set.h"
16 #include "cc/resources/picture_pile_impl.h"
17 #include "skia/ext/refptr.h"
18 #include "third_party/skia/include/core/SkPicture.h"
22 struct AppendQuadsData
;
24 class MicroBenchmarkImpl
;
26 class CC_EXPORT PictureLayerImpl
28 NON_EXPORTED_BASE(public PictureLayerTilingClient
) {
30 static scoped_ptr
<PictureLayerImpl
> Create(LayerTreeImpl
* tree_impl
, int id
) {
31 return make_scoped_ptr(new PictureLayerImpl(tree_impl
, id
));
33 virtual ~PictureLayerImpl();
35 // LayerImpl overrides.
36 virtual const char* LayerTypeAsString() const OVERRIDE
;
37 virtual scoped_ptr
<LayerImpl
> CreateLayerImpl(LayerTreeImpl
* tree_impl
)
39 virtual void PushPropertiesTo(LayerImpl
* layer
) OVERRIDE
;
40 virtual void AppendQuads(QuadSink
* quad_sink
,
41 AppendQuadsData
* append_quads_data
) OVERRIDE
;
42 virtual void UpdateTilePriorities() OVERRIDE
;
43 virtual void DidBecomeActive() OVERRIDE
;
44 virtual void DidBeginTracing() OVERRIDE
;
45 virtual void DidLoseOutputSurface() OVERRIDE
;
46 virtual void CalculateContentsScale(float ideal_contents_scale
,
47 float device_scale_factor
,
48 float page_scale_factor
,
49 bool animating_transform_to_screen
,
50 float* contents_scale_x
,
51 float* contents_scale_y
,
52 gfx::Size
* content_bounds
) OVERRIDE
;
53 virtual skia::RefPtr
<SkPicture
> GetPicture() OVERRIDE
;
55 // PictureLayerTilingClient overrides.
56 virtual scoped_refptr
<Tile
> CreateTile(PictureLayerTiling
* tiling
,
57 gfx::Rect content_rect
) OVERRIDE
;
58 virtual void UpdatePile(Tile
* tile
) OVERRIDE
;
59 virtual gfx::Size
CalculateTileSize(
60 gfx::Size content_bounds
) const OVERRIDE
;
61 virtual const Region
* GetInvalidation() OVERRIDE
;
62 virtual const PictureLayerTiling
* GetTwinTiling(
63 const PictureLayerTiling
* tiling
) const OVERRIDE
;
65 // PushPropertiesTo active tree => pending tree.
66 void SyncTiling(const PictureLayerTiling
* tiling
);
68 // Mask-related functions
69 void SetIsMask(bool is_mask
);
70 virtual ResourceProvider::ResourceId
ContentsResourceId() const OVERRIDE
;
72 virtual size_t GPUMemoryUsageInBytes() const OVERRIDE
;
74 virtual void RunMicroBenchmark(MicroBenchmarkImpl
* benchmark
) OVERRIDE
;
76 void SetShouldUseGpuRasterization(bool should_use_gpu_rasterization
);
77 bool should_use_gpu_rasterization() const {
78 return should_use_gpu_rasterization_
;
82 PictureLayerImpl(LayerTreeImpl
* tree_impl
, int id
);
83 PictureLayerTiling
* AddTiling(float contents_scale
);
84 void RemoveTiling(float contents_scale
);
85 void RemoveAllTilings();
86 void SyncFromActiveLayer(const PictureLayerImpl
* other
);
87 void ManageTilings(bool animating_transform_to_screen
);
88 virtual bool ShouldAdjustRasterScale(
89 bool animating_transform_to_screen
) const;
90 virtual void RecalculateRasterScales(
91 bool animating_transform_to_screen
);
92 void CleanUpTilingsOnActiveLayer(
93 std::vector
<PictureLayerTiling
*> used_tilings
);
94 float MinimumContentsScale() const;
95 float SnappedContentsScale(float new_contents_scale
);
96 void UpdateLCDTextStatus(bool new_status
);
97 void ResetRasterScale();
98 void MarkVisibleResourcesAsRequired() const;
99 bool MarkVisibleTilesAsRequired(
100 PictureLayerTiling
* tiling
,
101 const PictureLayerTiling
* optional_twin_tiling
,
102 float contents_scale
,
104 const Region
& missing_region
) const;
106 void DoPostCommitInitializationIfNeeded() {
107 if (needs_post_commit_initialization_
)
108 DoPostCommitInitialization();
110 void DoPostCommitInitialization();
112 bool CanHaveTilings() const;
113 bool CanHaveTilingWithScale(float contents_scale
) const;
114 void SanityCheckTilingState() const;
116 virtual void GetDebugBorderProperties(
117 SkColor
* color
, float* width
) const OVERRIDE
;
118 virtual void AsValueInto(base::DictionaryValue
* dict
) const OVERRIDE
;
120 PictureLayerImpl
* twin_layer_
;
122 scoped_ptr
<PictureLayerTilingSet
> tilings_
;
123 scoped_refptr
<PicturePileImpl
> pile_
;
124 Region invalidation_
;
126 gfx::Transform last_screen_space_transform_
;
127 gfx::Size last_bounds_
;
128 float last_content_scale_
;
131 float ideal_page_scale_
;
132 float ideal_device_scale_
;
133 float ideal_source_scale_
;
134 float ideal_contents_scale_
;
136 float raster_page_scale_
;
137 float raster_device_scale_
;
138 float raster_source_scale_
;
139 float raster_contents_scale_
;
140 float low_res_raster_contents_scale_
;
142 bool raster_source_scale_was_animating_
;
143 bool is_using_lcd_text_
;
144 bool needs_post_commit_initialization_
;
145 // A sanity state check to make sure UpdateTilePriorities only gets called
146 // after a CalculateContentsScale/ManageTilings.
147 bool should_update_tile_priorities_
;
148 bool should_use_gpu_rasterization_
;
150 friend class PictureLayer
;
151 DISALLOW_COPY_AND_ASSIGN(PictureLayerImpl
);
156 #endif // CC_LAYERS_PICTURE_LAYER_IMPL_H_