Home | History | Annotate | Download | only in cc
      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 #ifndef CCLayerImpl_h
     27 #define CCLayerImpl_h
     28 
     29 #include "Color.h"
     30 #include "FloatRect.h"
     31 #include "IntRect.h"
     32 #include "TextStream.h"
     33 #include "TransformationMatrix.h"
     34 #include <wtf/OwnPtr.h>
     35 #include <wtf/PassRefPtr.h>
     36 #include <wtf/RefCounted.h>
     37 #include <wtf/text/WTFString.h>
     38 
     39 namespace WebCore {
     40 
     41 class LayerChromium;
     42 class LayerRendererChromium;
     43 class RenderSurfaceChromium;
     44 
     45 class CCLayerImpl : public RefCounted<CCLayerImpl> {
     46 public:
     47     static PassRefPtr<CCLayerImpl> create(LayerChromium* owner)
     48     {
     49         return adoptRef(new CCLayerImpl(owner));
     50     }
     51     // When this class gets subclasses, remember to add 'virtual' here.
     52     virtual ~CCLayerImpl();
     53     void resetOwner() { m_owner = 0; }
     54     LayerChromium* owner() const { return m_owner; }
     55 
     56 #ifndef NDEBUG
     57     int debugID() const { return m_debugID; }
     58 #endif
     59 
     60     CCLayerImpl* superlayer() const;
     61     CCLayerImpl* maskLayer() const;
     62     CCLayerImpl* replicaLayer() const;
     63 
     64     virtual void draw(const IntRect& contentRect);
     65     virtual void updateCompositorResources();
     66     void unreserveContentsTexture();
     67     void bindContentsTexture();
     68 
     69     // Returns true if this layer has content to draw.
     70     virtual bool drawsContent() const;
     71 
     72     // Returns true if any of the layer's descendants has content to draw.
     73     bool descendantsDrawsContent();
     74 
     75     void cleanupResources();
     76 
     77     void setAnchorPoint(const FloatPoint& anchorPoint) { m_anchorPoint = anchorPoint; }
     78     const FloatPoint& anchorPoint() const { return m_anchorPoint; }
     79 
     80     void setAnchorPointZ(float anchorPointZ) { m_anchorPointZ = anchorPointZ; }
     81     float anchorPointZ() const { return m_anchorPointZ; }
     82 
     83     void setMasksToBounds(bool masksToBounds) { m_masksToBounds = masksToBounds; }
     84     bool masksToBounds() const { return m_masksToBounds; }
     85 
     86     void setOpacity(float opacity) { m_opacity = opacity; }
     87     float opacity() const { return m_opacity; }
     88 
     89     void setPosition(const FloatPoint& position) { m_position = position; }
     90     const FloatPoint& position() const { return m_position; }
     91 
     92     void setPreserves3D(bool preserves3D) { m_preserves3D = preserves3D; }
     93     bool preserves3D() const { return m_preserves3D; }
     94 
     95     void setSublayerTransform(const TransformationMatrix& sublayerTransform) { m_sublayerTransform = sublayerTransform; }
     96     const TransformationMatrix& sublayerTransform() const { return m_sublayerTransform; }
     97 
     98     void setTransform(const TransformationMatrix& transform) { m_transform = transform; }
     99     const TransformationMatrix& transform() const { return m_transform; }
    100 
    101     void setName(const String& name) { m_name = name; }
    102     const String& name() const { return m_name; }
    103 
    104     // Debug layer border - visual effect only, do not change geometry/clipping/etc.
    105     void setDebugBorderColor(Color c) { m_debugBorderColor = c; }
    106     Color debugBorderColor() const { return m_debugBorderColor; }
    107     void setDebugBorderWidth(float width) { m_debugBorderWidth = width; }
    108     float debugBorderWidth() const { return m_debugBorderWidth; }
    109 
    110     void drawDebugBorder();
    111 
    112     void setLayerRenderer(LayerRendererChromium*);
    113     LayerRendererChromium* layerRenderer() const { return m_layerRenderer.get(); }
    114 
    115     RenderSurfaceChromium* createRenderSurface();
    116 
    117     RenderSurfaceChromium* renderSurface() const { return m_renderSurface.get(); }
    118     void clearRenderSurface() { m_renderSurface.clear(); }
    119     float drawDepth() const { return m_drawDepth; }
    120     void setDrawDepth(float depth) { m_drawDepth = depth; }
    121     float drawOpacity() const { return m_drawOpacity; }
    122     void setDrawOpacity(float opacity) { m_drawOpacity = opacity; }
    123     const IntRect& scissorRect() const { return m_scissorRect; }
    124     void setScissorRect(const IntRect& rect) { m_scissorRect = rect; }
    125     RenderSurfaceChromium* targetRenderSurface() const { return m_targetRenderSurface; }
    126     void setTargetRenderSurface(RenderSurfaceChromium* surface) { m_targetRenderSurface = surface; }
    127 
    128     bool doubleSided() const { return m_doubleSided; }
    129     void setDoubleSided(bool doubleSided) { m_doubleSided = doubleSided; }
    130     const IntSize& bounds() const { return m_bounds; }
    131     void setBounds(const IntSize& bounds) { m_bounds = bounds; }
    132 
    133     // Returns the rect containtaining this layer in the current view's coordinate system.
    134     const IntRect getDrawRect() const;
    135 
    136     const TransformationMatrix& drawTransform() const { return m_drawTransform; }
    137     void setDrawTransform(const TransformationMatrix& matrix) { m_drawTransform = matrix; }
    138     const IntRect& drawableContentRect() const { return m_drawableContentRect; }
    139     void setDrawableContentRect(const IntRect& rect) { m_drawableContentRect = rect; }
    140 
    141     virtual void dumpLayerProperties(TextStream&, int indent) const;
    142 
    143 protected:
    144     // For now, CCLayers are owned directly by a LayerChromium.
    145     LayerChromium* m_owner;
    146     explicit CCLayerImpl(LayerChromium*);
    147 
    148     static void writeIndent(TextStream&, int indent);
    149 
    150 private:
    151     // Properties synchronized from the associated LayerChromium.
    152     FloatPoint m_anchorPoint;
    153     float m_anchorPointZ;
    154     IntSize m_bounds;
    155 
    156     // Whether the "back" of this layer should draw.
    157     bool m_doubleSided;
    158 
    159     bool m_masksToBounds;
    160     float m_opacity;
    161     FloatPoint m_position;
    162     bool m_preserves3D;
    163     TransformationMatrix m_sublayerTransform;
    164     TransformationMatrix m_transform;
    165 
    166     // Properties owned exclusively by this CCLayerImpl.
    167     // Debugging.
    168 #ifndef NDEBUG
    169     int m_debugID;
    170 #endif
    171 
    172     String m_name;
    173 
    174     // Render surface this layer draws into. This is a surface that can belong
    175     // either to this layer (if m_targetRenderSurface == m_renderSurface) or
    176     // to an ancestor of this layer. The target render surface determines the
    177     // coordinate system the layer's transforms are relative to.
    178     RenderSurfaceChromium* m_targetRenderSurface;
    179 
    180     // The global depth value of the center of the layer. This value is used
    181     // to sort layers from back to front.
    182     float m_drawDepth;
    183     float m_drawOpacity;
    184 
    185     // Debug borders.
    186     Color m_debugBorderColor;
    187     float m_debugBorderWidth;
    188 
    189     TransformationMatrix m_drawTransform;
    190 
    191     // The scissor rectangle that should be used when this layer is drawn.
    192     // Inherited by the parent layer and further restricted if this layer masks
    193     // to bounds.
    194     IntRect m_scissorRect;
    195 
    196     // Render surface associated with this layer. The layer and its descendants
    197     // will render to this surface.
    198     OwnPtr<RenderSurfaceChromium> m_renderSurface;
    199 
    200     // Hierarchical bounding rect containing the layer and its descendants.
    201     IntRect m_drawableContentRect;
    202 
    203     // Points to the layer renderer that updates and draws this layer.
    204     RefPtr<LayerRendererChromium> m_layerRenderer;
    205 };
    206 
    207 }
    208 
    209 #endif // CCLayerImpl_h
    210