• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2010, The Android Open Source Project
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *  * Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  *  * Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */
25 
26 #ifndef TiledPage_h
27 #define TiledPage_h
28 
29 #if USE(ACCELERATED_COMPOSITING)
30 
31 #include "BaseTile.h"
32 #include "SkCanvas.h"
33 #include "SkRegion.h"
34 
35 #include "TilePainter.h"
36 
37 namespace WebCore {
38 
39 class GLWebViewState;
40 class IntRect;
41 
42 /**
43  * The TiledPage represents a map of BaseTiles covering the viewport. Each
44  * GLWebViewState contains two TiledPages, one to display the page at the
45  * current scale factor, and another in the background that we use to paint the
46  * page at a different scale factor.  For instance, when we zoom using one
47  * TiledPage its tiles are scaled in hardware and therefore are subject to a
48  * loss of quality. To address this when the user finishes zooming we paint the
49  * background TilePage at the new scale factor.  When the background TilePage is
50  * ready, we swap it with the currently displaying TiledPage.
51  */
52 class TiledPage : public TilePainter {
53 public:
54     enum PrepareBounds {
55         ExpandedBounds = 0,
56         VisibleBounds = 1
57     };
58     enum SwapMethod {
59         SwapWhateverIsReady = 0,
60         SwapWholePage = 1
61     };
62 
63     TiledPage(int id, GLWebViewState* state);
64     ~TiledPage();
65 
66     // returns the other TiledPage who shares the same GLWebViewState
67     TiledPage* sibling();
68 
69     // prepare the page for display on the screen
70     void prepare(bool goingDown, bool goingLeft, const SkIRect& tileBounds, PrepareBounds bounds);
71 
72     // update tiles with inval information, return true if visible ones are
73     // dirty (and thus repaint needed)
74     bool updateTileDirtiness(const SkIRect& tileBounds);
75 
76     // check to see if the page is ready for display
77 
78     // swap 'buffers' by swapping each modified texture
79     bool swapBuffersIfReady(const SkIRect& tileBounds, float scale, SwapMethod swap);
80     // draw the page on the screen
81     void draw(float transparency, const SkIRect& tileBounds);
82 
83     // TilePainter implementation
84     // used by individual tiles to generate the bitmap for their tile
85     bool paint(BaseTile*, SkCanvas*, unsigned int*);
86     void paintExtra(SkCanvas*);
87 
88     // used by individual tiles to get the information about the current picture
glWebViewState()89     GLWebViewState* glWebViewState() { return m_glWebViewState; }
90 
scale()91     float scale() const { return m_scale; }
92 
93     //TODO: clear all textures if this is called with a new value
setScale(float scale)94     void setScale(float scale) { m_scale = scale; m_invScale = 1 / scale; }
95 
96     void invalidateRect(const IntRect& invalRect, const unsigned int pictureCount);
97     void discardTextures();
98     void updateBaseTileSize();
scrollingDown()99     bool scrollingDown() { return m_scrollingDown; }
expandedTileBounds()100     SkIRect* expandedTileBounds() { return &m_expandedTileBounds; }
isPrefetchPage()101     bool isPrefetchPage() { return m_isPrefetchPage; }
setIsPrefetchPage(bool isPrefetch)102     void setIsPrefetchPage(bool isPrefetch) { m_isPrefetchPage = isPrefetch; }
103 
104 private:
105     void prepareRow(bool goingLeft, int tilesInRow, int firstTileX, int y, const SkIRect& tileBounds);
106 
107     BaseTile* getBaseTile(int x, int y) const;
108 
109     // array of tiles used to compose a page. The tiles are allocated in the
110     // constructor to prevent them from potentially being allocated on the stack
111     BaseTile* m_baseTiles;
112     // stores the number of tiles in the m_baseTiles array. This enables us to
113     // quickly iterate over the array without have to check it's size
114     int m_baseTileSize;
115     int m_id;
116     float m_scale;
117     float m_invScale;
118     GLWebViewState* m_glWebViewState;
119 
120     // used to identify the tiles that have been invalidated (marked dirty) since
121     // the last time updateTileState() has been called. The region is stored in
122     // terms of the (x,y) coordinates used to determine the location of the tile
123     // within the page, not in content/view pixel coordinates.
124     SkRegion m_invalRegion;
125 
126     // inval regions in content coordinates
127     SkRegion m_invalTilesRegion;
128     unsigned int m_latestPictureInval;
129     bool m_prepare;
130     bool m_scrollingDown;
131     SkIRect m_expandedTileBounds;
132     bool m_isPrefetchPage;
133 };
134 
135 } // namespace WebCore
136 
137 #endif // USE(ACCELERATED_COMPOSITING)
138 #endif // TiledPage_h
139