tiled_layer.h revision 90dce4d38c5ff5333bea97d859d4e484e27edf0c
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. 4 5#ifndef CC_LAYERS_TILED_LAYER_H_ 6#define CC_LAYERS_TILED_LAYER_H_ 7 8#include "cc/base/cc_export.h" 9#include "cc/layers/contents_scaling_layer.h" 10#include "cc/resources/layer_tiling_data.h" 11 12namespace cc { 13class LayerUpdater; 14class PrioritizedResourceManager; 15class PrioritizedResource; 16class UpdatableTile; 17 18class CC_EXPORT TiledLayer : public ContentsScalingLayer { 19 public: 20 enum TilingOption { 21 ALWAYS_TILE, 22 NEVER_TILE, 23 AUTO_TILE, 24 }; 25 26 // Layer implementation. 27 virtual void SetIsMask(bool is_mask) OVERRIDE; 28 virtual void PushPropertiesTo(LayerImpl* layer) OVERRIDE; 29 virtual bool BlocksPendingCommit() const OVERRIDE; 30 virtual bool DrawsContent() const OVERRIDE; 31 virtual void ReduceMemoryUsage() OVERRIDE; 32 virtual void SetNeedsDisplayRect(const gfx::RectF& dirty_rect) OVERRIDE; 33 virtual void SetLayerTreeHost(LayerTreeHost* layer_tree_host) OVERRIDE; 34 virtual void SetTexturePriorities(const PriorityCalculator& priority_calc) 35 OVERRIDE; 36 virtual Region VisibleContentOpaqueRegion() const OVERRIDE; 37 virtual void Update(ResourceUpdateQueue* queue, 38 const OcclusionTracker* occlusion, 39 RenderingStats* stats) OVERRIDE; 40 41 protected: 42 TiledLayer(); 43 virtual ~TiledLayer(); 44 45 void UpdateTileSizeAndTilingOption(); 46 void UpdateBounds(); 47 48 // Exposed to subclasses for testing. 49 void SetTileSize(gfx::Size size); 50 void SetTextureFormat(unsigned texture_format) { 51 texture_format_ = texture_format; 52 } 53 void SetBorderTexelOption(LayerTilingData::BorderTexelOption option); 54 size_t NumPaintedTiles() { return tiler_->tiles().size(); } 55 56 virtual LayerUpdater* Updater() const = 0; 57 virtual void CreateUpdaterIfNeeded() = 0; 58 59 // Set invalidations to be potentially repainted during Update(). 60 void InvalidateContentRect(gfx::Rect content_rect); 61 62 // Reset state on tiles that will be used for updating the layer. 63 void ResetUpdateState(); 64 65 // After preparing an update, returns true if more painting is needed. 66 bool NeedsIdlePaint(); 67 gfx::Rect IdlePaintRect(); 68 69 bool SkipsDraw() const { return skips_draw_; } 70 71 // Virtual for testing 72 virtual PrioritizedResourceManager* ResourceManager() const; 73 const LayerTilingData* TilerForTesting() const { return tiler_.get(); } 74 const PrioritizedResource* ResourceAtForTesting(int i, int j) const; 75 76 private: 77 virtual scoped_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl) 78 OVERRIDE; 79 80 void CreateTilerIfNeeded(); 81 void set_tiling_option(TilingOption tiling_option) { 82 tiling_option_ = tiling_option; 83 } 84 85 bool TileOnlyNeedsPartialUpdate(UpdatableTile* tile); 86 bool TileNeedsBufferedUpdate(UpdatableTile* tile); 87 88 void MarkOcclusionsAndRequestTextures(int left, 89 int top, 90 int right, 91 int bottom, 92 const OcclusionTracker* occlusion); 93 94 bool UpdateTiles(int left, 95 int top, 96 int right, 97 int bottom, 98 ResourceUpdateQueue* queue, 99 const OcclusionTracker* occlusion, 100 RenderingStats* stats, 101 bool* did_paint); 102 bool HaveTexturesForTiles(int left, 103 int top, 104 int right, 105 int bottom, 106 bool ignore_occlusions); 107 gfx::Rect MarkTilesForUpdate(int left, 108 int top, 109 int right, 110 int bottom, 111 bool ignore_occlusions); 112 void UpdateTileTextures(gfx::Rect paint_rect, 113 int left, 114 int top, 115 int right, 116 int bottom, 117 ResourceUpdateQueue* queue, 118 const OcclusionTracker* occlusion, 119 RenderingStats* stats); 120 void UpdateScrollPrediction(); 121 122 UpdatableTile* TileAt(int i, int j) const; 123 UpdatableTile* CreateTile(int i, int j); 124 125 bool IsSmallAnimatedLayer() const; 126 127 unsigned texture_format_; 128 bool skips_draw_; 129 bool failed_update_; 130 131 // Used for predictive painting. 132 gfx::Vector2d predicted_scroll_; 133 gfx::Rect predicted_visible_rect_; 134 gfx::Rect previous_visible_rect_; 135 gfx::Size previous_content_bounds_; 136 137 TilingOption tiling_option_; 138 scoped_ptr<LayerTilingData> tiler_; 139 140 DISALLOW_COPY_AND_ASSIGN(TiledLayer); 141}; 142 143} // namespace cc 144 145#endif // CC_LAYERS_TILED_LAYER_H_ 146