[chromium] Improved composited debug borders
[WebKit-https.git] / Source / WebCore / platform / graphics / chromium / cc / CCRenderSurface.h
1 /*
2  * Copyright (C) 2011 Google Inc. All rights reserved.
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  *
8  * 1.  Redistributions of source code must retain the above copyright
9  *     notice, this list of conditions and the following disclaimer.
10  * 2.  Redistributions in binary form must reproduce the above copyright
11  *     notice, this list of conditions and the following disclaimer in the
12  *     documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
15  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17  * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
18  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26
27 #ifndef CCRenderSurface_h
28 #define CCRenderSurface_h
29
30 #if USE(ACCELERATED_COMPOSITING)
31
32 #include "FilterOperations.h"
33 #include "FloatRect.h"
34 #include "IntRect.h"
35 #include "ProgramBinding.h"
36 #include "ShaderChromium.h"
37 #include "SkBitmap.h"
38 #include "TextureManager.h"
39 #include "TransformationMatrix.h"
40 #include "cc/CCLayerQuad.h"
41 #include <wtf/Noncopyable.h>
42
43 namespace WebCore {
44
45 class CCDamageTracker;
46 class CCSharedQuadState;
47 class CCLayerImpl;
48 class LayerRendererChromium;
49 class ManagedTexture;
50
51 class CCRenderSurface {
52     WTF_MAKE_NONCOPYABLE(CCRenderSurface);
53 public:
54     explicit CCRenderSurface(CCLayerImpl*);
55     ~CCRenderSurface();
56
57     bool prepareContentsTexture(LayerRendererChromium*);
58     void releaseContentsTexture();
59
60     void draw(LayerRendererChromium*, const FloatRect& surfaceDamageRect);
61
62     String name() const;
63     void dumpSurface(TextStream&, int indent) const;
64
65     FloatPoint contentRectCenter() const { return FloatRect(m_contentRect).center(); }
66
67     // Returns the rect that encloses the RenderSurface including any reflection.
68     FloatRect drawableContentRect() const;
69
70     float drawOpacity() const { return m_drawOpacity; }
71     void setDrawOpacity(float opacity) { m_drawOpacity = opacity; }
72
73     void setFilters(const FilterOperations& filters) { m_filters = filters; }
74     const FilterOperations& filters() const { return m_filters; }
75     SkBitmap applyFilters(LayerRendererChromium*);
76
77     void setNearestAncestorThatMovesPixels(CCRenderSurface* surface) { m_nearestAncestorThatMovesPixels = surface; }
78     const CCRenderSurface* nearestAncestorThatMovesPixels() const { return m_nearestAncestorThatMovesPixels; }
79
80     bool drawOpacityIsAnimating() const { return m_drawOpacityIsAnimating; }
81     void setDrawOpacityIsAnimating(bool drawOpacityIsAnimating) { m_drawOpacityIsAnimating = drawOpacityIsAnimating; }
82
83     void setDrawTransform(const TransformationMatrix& drawTransform) { m_drawTransform = drawTransform; }
84     const TransformationMatrix& drawTransform() const { return m_drawTransform; }
85
86     void setOriginTransform(const TransformationMatrix& originTransform) { m_originTransform = originTransform; }
87     const TransformationMatrix& originTransform() const { return m_originTransform; }
88
89     void setScreenSpaceTransform(const TransformationMatrix& screenSpaceTransform) { m_screenSpaceTransform = screenSpaceTransform; }
90     const TransformationMatrix& screenSpaceTransform() const { return m_screenSpaceTransform; }
91
92     void setReplicaDrawTransform(const TransformationMatrix& replicaDrawTransform) { m_replicaDrawTransform = replicaDrawTransform; }
93     const TransformationMatrix& replicaDrawTransform() const { return m_replicaDrawTransform; }
94
95     void setReplicaOriginTransform(const TransformationMatrix& replicaOriginTransform) { m_replicaOriginTransform = replicaOriginTransform; }
96     const TransformationMatrix& replicaOriginTransform() const { return m_replicaOriginTransform; }
97
98     void setReplicaScreenSpaceTransform(const TransformationMatrix& replicaScreenSpaceTransform) { m_replicaScreenSpaceTransform = replicaScreenSpaceTransform; }
99     const TransformationMatrix& replicaScreenSpaceTransform() const { return m_replicaScreenSpaceTransform; }
100
101     bool targetSurfaceTransformsAreAnimating() const { return m_targetSurfaceTransformsAreAnimating; }
102     void setTargetSurfaceTransformsAreAnimating(bool animating) { m_targetSurfaceTransformsAreAnimating = animating; }
103     bool screenSpaceTransformsAreAnimating() const { return m_screenSpaceTransformsAreAnimating; }
104     void setScreenSpaceTransformsAreAnimating(bool animating) { m_screenSpaceTransformsAreAnimating = animating; }
105
106     void setClipRect(const IntRect&);
107     const IntRect& clipRect() const { return m_clipRect; }
108
109     void setContentRect(const IntRect&);
110     const IntRect& contentRect() const { return m_contentRect; }
111
112     void setSkipsDraw(bool skipsDraw) { m_skipsDraw = skipsDraw; }
113     bool skipsDraw() const { return m_skipsDraw; }
114
115     void clearLayerList() { m_layerList.clear(); }
116     Vector<CCLayerImpl*>& layerList() { return m_layerList; }
117
118     void setMaskLayer(CCLayerImpl* maskLayer) { m_maskLayer = maskLayer; }
119
120     typedef ProgramBinding<VertexShaderPosTex, FragmentShaderRGBATexAlpha> Program;
121     typedef ProgramBinding<VertexShaderPosTex, FragmentShaderRGBATexAlphaMask> MaskProgram;
122     typedef ProgramBinding<VertexShaderQuad, FragmentShaderRGBATexAlphaAA> ProgramAA;
123     typedef ProgramBinding<VertexShaderQuad, FragmentShaderRGBATexAlphaMaskAA> MaskProgramAA;
124
125     ManagedTexture* contentsTexture() const { return m_contentsTexture.get(); }
126
127     int owningLayerId() const;
128
129     bool hasReplica();
130
131     void resetPropertyChangedFlag() { m_surfacePropertyChanged = false; }
132     bool surfacePropertyChanged() const;
133     bool surfacePropertyChangedOnlyFromDescendant() const;
134
135     CCDamageTracker* damageTracker() const { return m_damageTracker.get(); }
136
137     PassOwnPtr<CCSharedQuadState> createSharedQuadState() const;
138     PassOwnPtr<CCSharedQuadState> createReplicaSharedQuadState() const;
139
140 private:
141     void drawLayer(LayerRendererChromium*, CCLayerImpl*, const TransformationMatrix&, const SkBitmap& filterBitmap);
142     template <class T>
143     void drawSurface(LayerRendererChromium*, CCLayerImpl*, const TransformationMatrix& drawTransform, const TransformationMatrix& deviceTransform, const CCLayerQuad& deviceRect, const CCLayerQuad&, const T* program, int shaderMaskSamplerLocation, int shaderQuadLocation, int shaderEdgeLocation, const SkBitmap& filterBitmap);
144
145     CCLayerImpl* m_owningLayer;
146     CCLayerImpl* m_maskLayer;
147
148     IntRect m_contentRect;
149     bool m_skipsDraw;
150     bool m_surfacePropertyChanged;
151
152     OwnPtr<ManagedTexture> m_contentsTexture;
153     float m_drawOpacity;
154     bool m_drawOpacityIsAnimating;
155     TransformationMatrix m_drawTransform;
156     TransformationMatrix m_originTransform;
157     TransformationMatrix m_screenSpaceTransform;
158     TransformationMatrix m_replicaDrawTransform;
159     TransformationMatrix m_replicaOriginTransform;
160     TransformationMatrix m_replicaScreenSpaceTransform;
161     bool m_targetSurfaceTransformsAreAnimating;
162     bool m_screenSpaceTransformsAreAnimating;
163     FilterOperations m_filters;
164     IntRect m_clipRect;
165     Vector<CCLayerImpl*> m_layerList;
166
167     // The nearest ancestor target surface that will contain the contents of this surface, and that is going
168     // to move pixels within the surface (such as with a blur). This can point to itself.
169     CCRenderSurface* m_nearestAncestorThatMovesPixels;
170
171     OwnPtr<CCDamageTracker> m_damageTracker;
172
173     // Stored in the "surface space" where this damage can be used for scissoring.
174     FloatRect m_damageRect;
175
176     // For CCLayerIteratorActions
177     int m_targetRenderSurfaceLayerIndexHistory;
178     int m_currentLayerIndexHistory;
179     friend struct CCLayerIteratorActions;
180 };
181
182 }
183 #endif // USE(ACCELERATED_COMPOSITING)
184
185 #endif