summaryrefslogtreecommitdiffstats
path: root/cc/tiled_layer.h
blob: 6903fd54ff6cd58ce307dda003cb27d49be71d47 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// 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_TILED_LAYER_H_
#define CC_TILED_LAYER_H_

#include "cc/cc_export.h"
#include "cc/contents_scaling_layer.h"
#include "cc/layer_tiling_data.h"

namespace cc {
class LayerUpdater;
class PrioritizedResourceManager;
class PrioritizedResource;
class UpdatableTile;

class CC_EXPORT TiledLayer : public ContentsScalingLayer {
public:
    enum TilingOption { AlwaysTile, NeverTile, AutoTile };

    virtual void setIsMask(bool) OVERRIDE;

    virtual void pushPropertiesTo(LayerImpl*) OVERRIDE;

    virtual bool blocksPendingCommit() const OVERRIDE;

    virtual bool drawsContent() const OVERRIDE;

    virtual void setNeedsDisplayRect(const gfx::RectF&) OVERRIDE;

    virtual void setLayerTreeHost(LayerTreeHost*) OVERRIDE;

    virtual void setTexturePriorities(const PriorityCalculator&) OVERRIDE;

    virtual Region visibleContentOpaqueRegion() const OVERRIDE;

    virtual void update(ResourceUpdateQueue&, const OcclusionTracker*, RenderingStats*) OVERRIDE;

protected:
    TiledLayer();
    virtual ~TiledLayer();

    void updateTileSizeAndTilingOption();
    void updateBounds();

    // Exposed to subclasses for testing.
    void setTileSize(const gfx::Size&);
    void setTextureFormat(unsigned textureFormat) { m_textureFormat = textureFormat; }
    void setBorderTexelOption(LayerTilingData::BorderTexelOption);
    size_t numPaintedTiles() { return m_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& contentRect);

    // 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 m_skipsDraw; }

    // Virtual for testing
    virtual PrioritizedResourceManager* resourceManager() const;
    const LayerTilingData* tilerForTesting() const { return m_tiler.get(); }
    const PrioritizedResource* resourceAtForTesting(int, int) const;

private:
    virtual scoped_ptr<LayerImpl> createLayerImpl(LayerTreeImpl* treeImpl) OVERRIDE;

    void createTilerIfNeeded();
    void setTilingOption(TilingOption);

    bool tileOnlyNeedsPartialUpdate(UpdatableTile*);
    bool tileNeedsBufferedUpdate(UpdatableTile*);

    void markOcclusionsAndRequestTextures(int left, int top, int right, int bottom, const OcclusionTracker*);

    bool updateTiles(int left, int top, int right, int bottom, ResourceUpdateQueue&, const OcclusionTracker*, RenderingStats*, bool& didPaint);
    bool haveTexturesForTiles(int left, int top, int right, int bottom, bool ignoreOcclusions);
    gfx::Rect markTilesForUpdate(int left, int top, int right, int bottom, bool ignoreOcclusions);
    void updateTileTextures(const gfx::Rect& paintRect, int left, int top, int right, int bottom, ResourceUpdateQueue&, const OcclusionTracker*, RenderingStats*);
    void updateScrollPrediction();

    UpdatableTile* tileAt(int, int) const;
    UpdatableTile* createTile(int, int);

    bool isSmallAnimatedLayer() const;

    unsigned m_textureFormat;
    bool m_skipsDraw;
    bool m_failedUpdate;

    // Used for predictive painting.
    gfx::Vector2d m_predictedScroll;
    gfx::Rect m_predictedVisibleRect;
    gfx::Rect m_previousVisibleRect;
    gfx::Size m_previousContentBounds;

    TilingOption m_tilingOption;
    scoped_ptr<LayerTilingData> m_tiler;
};

}
#endif  // CC_TILED_LAYER_H_