Add @VisibleForTesting to fix ChromePublic release build.
[chromium-blink-merge.git] / cc / layers / picture_layer_impl.h
blob119b0d4f719aff44aff0f096c7cbabb52f410f33
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_
8 #include <map>
9 #include <string>
10 #include <vector>
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"
22 namespace cc {
24 struct AppendQuadsData;
25 class MicroBenchmarkImpl;
26 class Tile;
28 class CC_EXPORT PictureLayerImpl
29 : public LayerImpl,
30 NON_EXPORTED_BASE(public PictureLayerTilingClient) {
31 public:
32 static scoped_ptr<PictureLayerImpl> Create(
33 LayerTreeImpl* tree_impl,
34 int id,
35 bool is_mask,
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 TilePriority::PriorityBin GetMaxTilePriorityBin() 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;
96 // Virtual for testing.
97 virtual bool HasValidTilePriorities() const;
99 // Used for benchmarking
100 RasterSource* GetRasterSource() const { return raster_source_.get(); }
102 protected:
103 friend class LayerRasterTileIterator;
104 using TileRequirementCheck = bool (PictureLayerTiling::*)(const Tile*) const;
106 PictureLayerImpl(LayerTreeImpl* tree_impl,
107 int id,
108 bool is_mask,
109 scoped_refptr<SyncedScrollOffset> scroll_offset);
110 PictureLayerTiling* AddTiling(float contents_scale);
111 void RemoveAllTilings();
112 void AddTilingsForRasterScale();
113 virtual bool ShouldAdjustRasterScale() const;
114 virtual void RecalculateRasterScales();
115 void CleanUpTilingsOnActiveLayer(
116 const std::vector<PictureLayerTiling*>& used_tilings);
117 float MinimumContentsScale() const;
118 float MaximumContentsScale() const;
119 void ResetRasterScale();
120 void UpdateViewportRectForTilePriorityInContentSpace();
121 PictureLayerImpl* GetRecycledTwinLayer() const;
123 void SanityCheckTilingState() const;
124 bool ShouldAdjustRasterScaleDuringScaleAnimations() const;
126 void GetDebugBorderProperties(SkColor* color, float* width) const override;
127 void GetAllPrioritizedTilesForTracing(
128 std::vector<PrioritizedTile>* prioritized_tiles) const override;
129 void AsValueInto(base::trace_event::TracedValue* dict) const override;
131 virtual void UpdateIdealScales();
132 float MaximumTilingContentsScale() const;
133 scoped_ptr<PictureLayerTilingSet> CreatePictureLayerTilingSet();
135 PictureLayerImpl* twin_layer_;
137 scoped_ptr<PictureLayerTilingSet> tilings_;
138 scoped_refptr<RasterSource> raster_source_;
139 Region invalidation_;
141 float ideal_page_scale_;
142 float ideal_device_scale_;
143 float ideal_source_scale_;
144 float ideal_contents_scale_;
146 float raster_page_scale_;
147 float raster_device_scale_;
148 float raster_source_scale_;
149 float raster_contents_scale_;
150 float low_res_raster_contents_scale_;
152 bool raster_source_scale_is_fixed_;
153 bool was_screen_space_transform_animating_;
154 bool only_used_low_res_last_append_quads_;
155 const bool is_mask_;
157 bool nearest_neighbor_;
159 // Any draw properties derived from |transform|, |viewport|, and |clip|
160 // parameters in LayerTreeHostImpl::SetExternalDrawConstraints are not valid
161 // for prioritizing tiles during resourceless software draws. This is because
162 // resourceless software draws can have wildly different transforms/viewports
163 // from regular draws. Save a copy of the required draw properties of the last
164 // frame that has a valid viewport for prioritizing tiles.
165 gfx::Rect visible_rect_for_tile_priority_;
166 gfx::Rect viewport_rect_for_tile_priority_in_content_space_;
168 gfx::Size gpu_raster_max_texture_size_;
170 // List of tilings that were used last time we appended quads. This can be
171 // used as an optimization not to remove tilings if they are still being
172 // drawn. Note that accessing this vector should only be done in the context
173 // of comparing pointers, since objects pointed to are not guaranteed to
174 // exist.
175 std::vector<PictureLayerTiling*> last_append_quads_tilings_;
177 DISALLOW_COPY_AND_ASSIGN(PictureLayerImpl);
180 } // namespace cc
182 #endif // CC_LAYERS_PICTURE_LAYER_IMPL_H_