Home | History | Annotate | Download | only in android
      1 /*
      2  * Copyright (C) 2009 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #ifndef GraphicsLayerAndroid_h
     18 #define GraphicsLayerAndroid_h
     19 
     20 #if USE(ACCELERATED_COMPOSITING)
     21 
     22 #include "FloatRect.h"
     23 #include "Frame.h"
     24 #include "GraphicsLayer.h"
     25 #include "GraphicsLayerClient.h"
     26 #include "LayerAndroid.h"
     27 #include "RefPtr.h"
     28 #include "SkBitmapRef.h"
     29 #include "Vector.h"
     30 
     31 class FloatPoint3D;
     32 class Image;
     33 class SkBitmapRef;
     34 class SkRegion;
     35 
     36 namespace WebCore {
     37 
     38 class ScrollableLayerAndroid;
     39 
     40 class GraphicsLayerAndroid : public GraphicsLayer {
     41 public:
     42 
     43     GraphicsLayerAndroid(GraphicsLayerClient*);
     44     virtual ~GraphicsLayerAndroid();
     45 
     46     virtual void setName(const String&);
     47 
     48     // for hosting this GraphicsLayer in a native layer hierarchy
     49     virtual NativeLayer nativeLayer() const;
     50 
     51     virtual bool setChildren(const Vector<GraphicsLayer*>&);
     52     virtual void addChild(GraphicsLayer*);
     53     virtual void addChildAtIndex(GraphicsLayer*, int index);
     54     virtual void addChildAbove(GraphicsLayer* layer, GraphicsLayer* sibling);
     55     virtual void addChildBelow(GraphicsLayer* layer, GraphicsLayer* sibling);
     56     virtual bool replaceChild(GraphicsLayer* oldChild, GraphicsLayer* newChild);
     57 
     58     virtual void removeFromParent();
     59 
     60     virtual void setPosition(const FloatPoint&);
     61     virtual void setPreserves3D(bool b);
     62     virtual void setAnchorPoint(const FloatPoint3D&);
     63     virtual void setSize(const FloatSize&);
     64 
     65     virtual void setBackfaceVisibility(bool b);
     66     virtual void setTransform(const TransformationMatrix&);
     67 
     68     virtual void setChildrenTransform(const TransformationMatrix&);
     69 
     70     virtual void setMaskLayer(GraphicsLayer*);
     71     virtual void setMasksToBounds(bool);
     72     virtual void setDrawsContent(bool);
     73 
     74     virtual void setBackgroundColor(const Color&);
     75     virtual void clearBackgroundColor();
     76 
     77     virtual void setContentsOpaque(bool);
     78 
     79     virtual void setOpacity(float);
     80 
     81     virtual void setNeedsDisplay();
     82     virtual void setNeedsDisplayInRect(const FloatRect&);
     83 
     84     virtual bool addAnimation(const KeyframeValueList& valueList,
     85                               const IntSize& boxSize,
     86                               const Animation* anim,
     87                               const String& keyframesName,
     88                               double beginTime);
     89     bool createTransformAnimationsFromKeyframes(const KeyframeValueList&,
     90                                                 const Animation*,
     91                                                 const String& keyframesName,
     92                                                 double beginTime,
     93                                                 const IntSize& boxSize);
     94     bool createAnimationFromKeyframes(const KeyframeValueList&,
     95                                       const Animation*,
     96                                       const String& keyframesName,
     97                                       double beginTime);
     98 
     99     virtual void removeAnimationsForProperty(AnimatedPropertyID);
    100     virtual void removeAnimationsForKeyframes(const String& keyframesName);
    101     virtual void pauseAnimation(const String& keyframesName);
    102 
    103     virtual void suspendAnimations(double time);
    104     virtual void resumeAnimations();
    105 
    106     virtual void setContentsToImage(Image*);
    107     virtual void setContentsToMedia(PlatformLayer*);
    108     virtual PlatformLayer* platformLayer() const;
    109 
    110     void pauseDisplay(bool state);
    111 
    112 #ifndef NDEBUG
    113     virtual void setDebugBackgroundColor(const Color&);
    114     virtual void setDebugBorder(const Color&, float borderWidth);
    115 #endif
    116 
    117     virtual void setZPosition(float);
    118 
    119     void gatherRootLayers(Vector<const RenderLayer*>&);
    120     virtual void syncCompositingState();
    121     virtual void syncCompositingStateForThisLayerOnly();
    122     void notifyClientAnimationStarted();
    123 
    124     LayerAndroid* contentLayer() { return m_contentLayer; }
    125 
    126     static int instancesCount();
    127 
    128 private:
    129 
    130     void askForSync();
    131     void syncPositionState();
    132     void syncChildren();
    133     void syncMask();
    134 
    135     void updateFixedPosition();
    136     void updateScrollingLayers();
    137 
    138     // with SkPicture, we always repaint the entire layer's content.
    139     bool repaint();
    140     void needsNotifyClient();
    141 
    142     bool paintContext(SkPicture* context, const IntRect& rect);
    143 
    144     bool m_needsSyncChildren;
    145     bool m_needsSyncMask;
    146     bool m_needsRepaint;
    147     bool m_needsNotifyClient;
    148 
    149     bool m_haveContents;
    150     bool m_newImage;
    151     Image* m_image;
    152 
    153     SkRegion m_dirtyRegion;
    154 
    155     LayerAndroid* m_contentLayer;
    156     ScrollableLayerAndroid* m_foregroundLayer;
    157     LayerAndroid* m_foregroundClipLayer;
    158 };
    159 
    160 } // namespace WebCore
    161 
    162 
    163 #endif // USE(ACCELERATED_COMPOSITING)
    164 
    165 #endif // GraphicsLayerAndroid_h
    166