Home | History | Annotate | Download | only in chromium
      1 /*
      2  * Copyright (C) 2010 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 are
      6  * met:
      7  *
      8  *     * Redistributions of source code must retain the above copyright
      9  * notice, this list of conditions and the following disclaimer.
     10  *     * Redistributions in binary form must reproduce the above
     11  * copyright notice, this list of conditions and the following disclaimer
     12  * in the documentation and/or other materials provided with the
     13  * distribution.
     14  *     * Neither the name of Google Inc. nor the names of its
     15  * contributors may be used to endorse or promote products derived from
     16  * this software without specific prior written permission.
     17  *
     18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     29  */
     30 
     31 #ifndef GraphicsLayerChromium_h
     32 #define GraphicsLayerChromium_h
     33 
     34 #if USE(ACCELERATED_COMPOSITING)
     35 
     36 #include "GraphicsContext.h"
     37 #include "GraphicsLayer.h"
     38 
     39 namespace WebCore {
     40 
     41 class LayerChromium;
     42 
     43 class GraphicsLayerChromium : public GraphicsLayer {
     44 public:
     45     GraphicsLayerChromium(GraphicsLayerClient*);
     46     virtual ~GraphicsLayerChromium();
     47 
     48     virtual void setName(const String&);
     49 
     50     virtual bool setChildren(const Vector<GraphicsLayer*>&);
     51     virtual void addChild(GraphicsLayer*);
     52     virtual void addChildAtIndex(GraphicsLayer*, int index);
     53     virtual void addChildAbove(GraphicsLayer*, GraphicsLayer* sibling);
     54     virtual void addChildBelow(GraphicsLayer*, GraphicsLayer* sibling);
     55     virtual bool replaceChild(GraphicsLayer* oldChild, GraphicsLayer* newChild);
     56 
     57     virtual void removeFromParent();
     58 
     59     virtual void setPosition(const FloatPoint&);
     60     virtual void setAnchorPoint(const FloatPoint3D&);
     61     virtual void setSize(const FloatSize&);
     62 
     63     virtual void setTransform(const TransformationMatrix&);
     64 
     65     virtual void setChildrenTransform(const TransformationMatrix&);
     66 
     67     virtual void setPreserves3D(bool);
     68     virtual void setMasksToBounds(bool);
     69     virtual void setDrawsContent(bool);
     70     virtual void setMaskLayer(GraphicsLayer*);
     71 
     72     virtual void setBackgroundColor(const Color&);
     73     virtual void clearBackgroundColor();
     74 
     75     virtual void setContentsOpaque(bool);
     76     virtual void setBackfaceVisibility(bool);
     77 
     78     virtual void setReplicatedByLayer(GraphicsLayer*);
     79 
     80     virtual void setOpacity(float);
     81 
     82     virtual void setNeedsDisplay();
     83     virtual void setNeedsDisplayInRect(const FloatRect&);
     84     virtual void setContentsNeedsDisplay();
     85 
     86     virtual void setContentsRect(const IntRect&);
     87 
     88     virtual void setContentsToImage(Image*);
     89     virtual void setContentsToMedia(PlatformLayer*);
     90     virtual void setContentsToCanvas(PlatformLayer*);
     91 
     92     virtual PlatformLayer* platformLayer() const;
     93 
     94     virtual void setDebugBackgroundColor(const Color&);
     95     virtual void setDebugBorder(const Color&, float borderWidth);
     96 
     97     void notifySyncRequired()
     98     {
     99         if (m_client)
    100             m_client->notifySyncRequired(this);
    101     }
    102 
    103 private:
    104     void updateOpacityOnLayer();
    105 
    106     LayerChromium* primaryLayer() const  { return m_transformLayer.get() ? m_transformLayer.get() : m_layer.get(); }
    107     LayerChromium* hostLayerForSublayers() const;
    108     LayerChromium* layerForSuperlayer() const;
    109 
    110     void updateNames();
    111     void updateSublayerList();
    112     void updateLayerPosition();
    113     void updateLayerSize();
    114     void updateAnchorPoint();
    115     void updateTransform();
    116     void updateChildrenTransform();
    117     void updateMasksToBounds();
    118     void updateContentsOpaque();
    119     void updateBackfaceVisibility();
    120     void updateLayerPreserves3D();
    121     void updateLayerDrawsContent();
    122     void updateLayerBackgroundColor();
    123 
    124     void updateContentsImage();
    125     void updateContentsVideo();
    126     void updateContentsRect();
    127 
    128     void setupContentsLayer(LayerChromium*);
    129     LayerChromium* contentsLayer() const { return m_contentsLayer.get(); }
    130 
    131     String m_nameBase;
    132 
    133     RefPtr<LayerChromium> m_layer;
    134     RefPtr<LayerChromium> m_transformLayer;
    135     RefPtr<LayerChromium> m_contentsLayer;
    136 
    137     enum ContentsLayerPurpose {
    138         NoContentsLayer = 0,
    139         ContentsLayerForImage,
    140         ContentsLayerForVideo,
    141         ContentsLayerForCanvas,
    142     };
    143 
    144     ContentsLayerPurpose m_contentsLayerPurpose;
    145     bool m_contentsLayerHasBackgroundColor : 1;
    146 };
    147 
    148 } // namespace WebCore
    149 
    150 #endif // USE(ACCELERATED_COMPOSITING)
    151 
    152 #endif
    153