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