• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
getFirstLayer()62     LayerAndroid* getFirstLayer() const { return m_layers[0]; }
needsTexture()63     bool needsTexture() { return m_needsTexture; }
64     bool isBase();
65 
66     // don't allow transform fudging for merged layers - they need the transform
67     // static at paint time, and are always aligned to 0,0 doc coordinates.
allowTransformFudging()68     bool allowTransformFudging() const { return singleLayer(); }
69 
70     // TilePainter methods
71     virtual bool paint(SkCanvas* canvas);
72     virtual float opacity();
73     virtual Color* background();
74     virtual bool blitFromContents(Tile* tile);
75 
76 private:
77     IntRect computePrepareArea();
78     IntRect visibleContentArea(bool force3dContentVisible = false) const;
79     IntRect fullContentArea();
singleLayer()80     bool singleLayer() const { return m_layers.size() == 1; }
81     bool useAggressiveRendering();
82 
83     const TransformationMatrix* drawTransform();
84     IntRect m_fullContentArea;
85     TransformationMatrix m_drawTransform;
86 
87     SurfaceBacking* m_surfaceBacking;
88     bool m_needsTexture;
89     float m_maxZoomScale;
90     Vector<LayerAndroid*> m_layers;
91 
92     Color m_background;
93 };
94 
95 class LayerMergeState {
96 public:
LayerMergeState(Vector<Surface * > * const allGroups)97     LayerMergeState(Vector<Surface*>* const allGroups)
98         : surfaceList(allGroups)
99         , currentSurface(0)
100         , nonMergeNestedLevel(0)
101         , depth(0)
102         {}
103 
104     // vector storing all generated layer groups
105     Vector<Surface*>* const surfaceList;
106 
107     // currently merging group. if cleared, no more layers may join
108     Surface* currentSurface;
109 
110     // records depth within non-mergeable parents (clipping, fixed, scrolling)
111     // and disable merging therein.
112     int nonMergeNestedLevel;
113 
114     // counts layer tree depth for debugging
115     int depth;
116 };
117 
118 } // namespace WebCore
119 
120 #endif //#define Surface_h
121