// Copyright 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef CC_LAYERS_TILED_LAYER_H_ #define CC_LAYERS_TILED_LAYER_H_ #include "cc/base/cc_export.h" #include "cc/layers/contents_scaling_layer.h" #include "cc/resources/resource_format.h" #include "cc/tiles/layer_tiling_data.h" namespace cc { class LayerUpdater; class PrioritizedResourceManager; class PrioritizedResource; class UpdatableTile; class CC_EXPORT TiledLayer : public ContentsScalingLayer { public: enum TilingOption { ALWAYS_TILE, NEVER_TILE, AUTO_TILE, }; // Layer implementation. void SetIsMask(bool is_mask) override; void PushPropertiesTo(LayerImpl* layer) override; void ReduceMemoryUsage() override; void SetNeedsDisplayRect(const gfx::Rect& dirty_rect) override; void SetLayerTreeHost(LayerTreeHost* layer_tree_host) override; void SetTexturePriorities(const PriorityCalculator& priority_calc) override; SimpleEnclosedRegion VisibleContentOpaqueRegion() const override; bool Update(ResourceUpdateQueue* queue) override; void OnOutputSurfaceCreated() override; protected: explicit TiledLayer(const LayerSettings& settings); ~TiledLayer() override; void UpdateTileSizeAndTilingOption(); void UpdateBounds(); // Exposed to subclasses for testing. void SetTileSize(const gfx::Size& size); void SetTextureFormat(ResourceFormat texture_format) { texture_format_ = texture_format; } void SetBorderTexelOption(LayerTilingData::BorderTexelOption option); size_t NumPaintedTiles() { return tiler_->tiles().size(); } virtual LayerUpdater* Updater() const = 0; virtual void CreateUpdaterIfNeeded() = 0; // Set invalidations to be potentially repainted during Update(). void InvalidateContentRect(const gfx::Rect& content_rect); // Reset state on tiles that will be used for updating the layer. void ResetUpdateState(); // After preparing an update, returns true if more painting is needed. bool NeedsIdlePaint(); gfx::Rect IdlePaintRect(); bool SkipsDraw() const { return skips_draw_; } bool HasDrawableContent() const override; // Virtual for testing virtual PrioritizedResourceManager* ResourceManager(); const LayerTilingData* TilerForTesting() const { return tiler_.get(); } const PrioritizedResource* ResourceAtForTesting(int i, int j) const; private: scoped_ptr CreateLayerImpl(LayerTreeImpl* tree_impl) override; void CreateTilerIfNeeded(); void set_tiling_option(TilingOption tiling_option) { tiling_option_ = tiling_option; } bool TileOnlyNeedsPartialUpdate(UpdatableTile* tile); bool TileNeedsBufferedUpdate(UpdatableTile* tile); void RequestTextures(int left, int top, int right, int bottom); bool UpdateTiles(int left, int top, int right, int bottom, ResourceUpdateQueue* queue, bool* did_paint); bool HaveTexturesForTiles(int left, int top, int right, int bottom); void MarkTilesForUpdate(gfx::Rect* update_rect, gfx::Rect* paint_rect, int left, int top, int right, int bottom); void UpdateTileTextures(const gfx::Rect& update_rect, const gfx::Rect& paint_rect, int left, int top, int right, int bottom, ResourceUpdateQueue* queue); void UpdateScrollPrediction(); UpdatableTile* TileAt(int i, int j) const; UpdatableTile* CreateTile(int i, int j); bool IsSmallAnimatedLayer() const; ResourceFormat texture_format_; bool skips_draw_; bool failed_update_; // Used for predictive painting. gfx::Vector2d predicted_scroll_; gfx::Rect predicted_visible_rect_; gfx::Rect previous_visible_rect_; gfx::Size previous_content_bounds_; TilingOption tiling_option_; scoped_ptr tiler_; DISALLOW_COPY_AND_ASSIGN(TiledLayer); }; } // namespace cc #endif // CC_LAYERS_TILED_LAYER_H_