Home | History | Annotate | Download | only in android
      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 
     59     TiledPage(int id, GLWebViewState* state);
     60     ~TiledPage();
     61 
     62     // returns the other TiledPage who shares the same GLWebViewState
     63     TiledPage* sibling();
     64 
     65     // prepare the page for display on the screen
     66     void prepare(bool goingDown, bool goingLeft, const SkIRect& tileBounds, PrepareBounds bounds);
     67 
     68     // update tiles with inval information, return true if visible ones are
     69     // dirty (and thus repaint needed)
     70     bool updateTileDirtiness(const SkIRect& tileBounds);
     71 
     72     // returns true if the page can't draw the entire region (may still be stale)
     73     bool hasMissingContent(const SkIRect& tileBounds);
     74 
     75     bool isReady(const SkIRect& tileBounds);
     76 
     77     // swap 'buffers' by swapping each modified texture
     78     bool swapBuffersIfReady(const SkIRect& tileBounds, float scale);
     79     // save the transparency and bounds to be drawn in drawGL()
     80     void prepareForDrawGL(float transparency, const SkIRect& tileBounds);
     81     // draw the page on the screen
     82     void drawGL();
     83 
     84     // TilePainter implementation
     85     // used by individual tiles to generate the bitmap for their tile
     86     bool paint(BaseTile*, SkCanvas*, unsigned int*);
     87 
     88     // used by individual tiles to get the information about the current picture
     89     GLWebViewState* glWebViewState() { return m_glWebViewState; }
     90 
     91     float scale() const { return m_scale; }
     92 
     93     //TODO: clear all textures if this is called with a new value
     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();
     99     bool scrollingDown() { return m_scrollingDown; }
    100     bool isPrefetchPage() { return m_isPrefetchPage; }
    101     void setIsPrefetchPage(bool isPrefetch) { m_isPrefetchPage = isPrefetch; }
    102 
    103 private:
    104     void prepareRow(bool goingLeft, int tilesInRow, int firstTileX, int y, const SkIRect& tileBounds);
    105 
    106     BaseTile* getBaseTile(int x, int y) const;
    107 
    108     // array of tiles used to compose a page. The tiles are allocated in the
    109     // constructor to prevent them from potentially being allocated on the stack
    110     BaseTile* m_baseTiles;
    111     // stores the number of tiles in the m_baseTiles array. This enables us to
    112     // quickly iterate over the array without have to check it's size
    113     int m_baseTileSize;
    114     int m_id;
    115     float m_scale;
    116     float m_invScale;
    117     GLWebViewState* m_glWebViewState;
    118 
    119     // used to identify the tiles that have been invalidated (marked dirty) since
    120     // the last time updateTileState() has been called. The region is stored in
    121     // terms of the (x,y) coordinates used to determine the location of the tile
    122     // within the page, not in content/view pixel coordinates.
    123     SkRegion m_invalRegion;
    124 
    125     // inval regions in content coordinates
    126     SkRegion m_invalTilesRegion;
    127     unsigned int m_latestPictureInval;
    128     bool m_prepare;
    129     bool m_scrollingDown;
    130     bool m_isPrefetchPage;
    131 
    132     // info saved in prepare, used in drawGL()
    133     bool m_willDraw;
    134     SkIRect m_tileBounds;
    135     float m_transparency;
    136 };
    137 
    138 } // namespace WebCore
    139 
    140 #endif // USE(ACCELERATED_COMPOSITING)
    141 #endif // TiledPage_h
    142