1 // Copyright 2011 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_TILED_LAYER_H_
6 #define CC_LAYERS_TILED_LAYER_H_
8 #include "cc/base/cc_export.h"
9 #include "cc/layers/contents_scaling_layer.h"
10 #include "cc/resources/layer_tiling_data.h"
11 #include "cc/resources/resource_format.h"
15 class PrioritizedResourceManager
;
16 class PrioritizedResource
;
19 class CC_EXPORT TiledLayer
: public ContentsScalingLayer
{
27 // Layer implementation.
28 virtual void SetIsMask(bool is_mask
) override
;
29 virtual void PushPropertiesTo(LayerImpl
* layer
) override
;
30 virtual void ReduceMemoryUsage() override
;
31 virtual void SetNeedsDisplayRect(const gfx::Rect
& dirty_rect
) override
;
32 virtual void SetLayerTreeHost(LayerTreeHost
* layer_tree_host
) override
;
33 virtual void SetTexturePriorities(const PriorityCalculator
& priority_calc
)
35 virtual SimpleEnclosedRegion
VisibleContentOpaqueRegion() const override
;
36 virtual bool Update(ResourceUpdateQueue
* queue
,
37 const OcclusionTracker
<Layer
>* occlusion
) override
;
38 virtual void OnOutputSurfaceCreated() override
;
42 virtual ~TiledLayer();
44 void UpdateTileSizeAndTilingOption();
47 // Exposed to subclasses for testing.
48 void SetTileSize(const gfx::Size
& size
);
49 void SetTextureFormat(ResourceFormat texture_format
) {
50 texture_format_
= texture_format
;
52 void SetBorderTexelOption(LayerTilingData::BorderTexelOption option
);
53 size_t NumPaintedTiles() { return tiler_
->tiles().size(); }
55 virtual LayerUpdater
* Updater() const = 0;
56 virtual void CreateUpdaterIfNeeded() = 0;
58 // Set invalidations to be potentially repainted during Update().
59 void InvalidateContentRect(const gfx::Rect
& content_rect
);
61 // Reset state on tiles that will be used for updating the layer.
62 void ResetUpdateState();
64 // After preparing an update, returns true if more painting is needed.
65 bool NeedsIdlePaint();
66 gfx::Rect
IdlePaintRect();
68 bool SkipsDraw() const { return skips_draw_
; }
70 virtual bool HasDrawableContent() const override
;
72 // Virtual for testing
73 virtual PrioritizedResourceManager
* ResourceManager();
74 const LayerTilingData
* TilerForTesting() const { return tiler_
.get(); }
75 const PrioritizedResource
* ResourceAtForTesting(int i
, int j
) const;
78 virtual scoped_ptr
<LayerImpl
> CreateLayerImpl(LayerTreeImpl
* tree_impl
)
81 void CreateTilerIfNeeded();
82 void set_tiling_option(TilingOption tiling_option
) {
83 tiling_option_
= tiling_option
;
86 bool TileOnlyNeedsPartialUpdate(UpdatableTile
* tile
);
87 bool TileNeedsBufferedUpdate(UpdatableTile
* tile
);
89 void MarkOcclusionsAndRequestTextures(
94 const OcclusionTracker
<Layer
>* occlusion
);
96 bool UpdateTiles(int left
,
100 ResourceUpdateQueue
* queue
,
101 const OcclusionTracker
<Layer
>* occlusion
,
103 bool HaveTexturesForTiles(int left
,
107 bool ignore_occlusions
);
108 void MarkTilesForUpdate(gfx::Rect
* update_rect
,
109 gfx::Rect
* paint_rect
,
114 bool ignore_occlusions
);
115 void UpdateTileTextures(const gfx::Rect
& update_rect
,
116 const gfx::Rect
& paint_rect
,
121 ResourceUpdateQueue
* queue
,
122 const OcclusionTracker
<Layer
>* occlusion
);
123 void UpdateScrollPrediction();
125 UpdatableTile
* TileAt(int i
, int j
) const;
126 UpdatableTile
* CreateTile(int i
, int j
);
128 bool IsSmallAnimatedLayer() const;
130 ResourceFormat texture_format_
;
134 // Used for predictive painting.
135 gfx::Vector2d predicted_scroll_
;
136 gfx::Rect predicted_visible_rect_
;
137 gfx::Rect previous_visible_rect_
;
138 gfx::Size previous_content_bounds_
;
140 TilingOption tiling_option_
;
141 scoped_ptr
<LayerTilingData
> tiler_
;
143 DISALLOW_COPY_AND_ASSIGN(TiledLayer
);
148 #endif // CC_LAYERS_TILED_LAYER_H_