Home | History | Annotate | Download | only in rendering
      1 /*
      2  * Copyright 2012, 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 Surface_h
     27 #define Surface_h
     28 
     29 #include "Color.h"
     30 #include "IntRect.h"
     31 #include "TilePainter.h"
     32 #include "Vector.h"
     33 
     34 class SkCanvas;
     35 class SkRegion;
     36 
     37 namespace WebCore {
     38 
     39 class Tile;
     40 class SurfaceBacking;
     41 class LayerAndroid;
     42 class TexturesResult;
     43 
     44 class Surface : public TilePainter {
     45 public:
     46     Surface();
     47     virtual ~Surface();
     48 
     49     bool tryUpdateSurface(Surface* oldSurface);
     50 
     51     void addLayer(LayerAndroid* layer, const TransformationMatrix& transform);
     52     void prepareGL(bool layerTilesDisabled, bool updateWithBlit);
     53     bool drawGL(bool layerTilesDisabled);
     54     void swapTiles(bool calculateFrameworkInvals);
     55     void addFrameworkInvals();
     56     bool isReady();
     57     bool isMissingContent();
     58     bool canUpdateWithBlit();
     59 
     60     void computeTexturesAmount(TexturesResult* result);
     61 
     62     LayerAndroid* getFirstLayer() const { return m_layers[0]; }
     63     bool needsTexture() { return m_needsTexture; }
     64     bool hasText() { return m_hasText; }
     65     bool isBase();
     66 
     67     // don't allow transform fudging for merged layers - they need the transform
     68     // static at paint time, and are always aligned to 0,0 doc coordinates.
     69     bool allowTransformFudging() const { return singleLayer(); }
     70 
     71     // TilePainter methods
     72     virtual bool paint(SkCanvas* canvas);
     73     virtual float opacity();
     74     virtual Color* background();
     75     virtual bool blitFromContents(Tile* tile);
     76 
     77 private:
     78     IntRect computePrepareArea();
     79     IntRect visibleContentArea(bool force3dContentVisible = false) const;
     80     IntRect fullContentArea();
     81     bool singleLayer() const { return m_layers.size() == 1; }
     82     bool useAggressiveRendering();
     83 
     84     const TransformationMatrix* drawTransform();
     85     IntRect m_fullContentArea;
     86     TransformationMatrix m_drawTransform;
     87 
     88     SurfaceBacking* m_surfaceBacking;
     89     bool m_needsTexture;
     90     bool m_hasText;
     91     Vector<LayerAndroid*> m_layers;
     92 
     93     Color m_background;
     94 };
     95 
     96 class LayerMergeState {
     97 public:
     98     LayerMergeState(Vector<Surface*>* const allGroups)
     99         : surfaceList(allGroups)
    100         , currentSurface(0)
    101         , nonMergeNestedLevel(0)
    102         , depth(0)
    103         {}
    104 
    105     // vector storing all generated layer groups
    106     Vector<Surface*>* const surfaceList;
    107 
    108     // currently merging group. if cleared, no more layers may join
    109     Surface* currentSurface;
    110 
    111     // records depth within non-mergeable parents (clipping, fixed, scrolling)
    112     // and disable merging therein.
    113     int nonMergeNestedLevel;
    114 
    115     // counts layer tree depth for debugging
    116     int depth;
    117 };
    118 
    119 } // namespace WebCore
    120 
    121 #endif //#define Surface_h
    122