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 "LayerContent.h"
     27 #include "PicturePile.h"
     28 #include "RefPtr.h"
     29 #include "ScrollableLayerAndroid.h"
     30 #include "SkBitmapRef.h"
     31 #include "Vector.h"
     32 
     33 class SkBitmapRef;
     34 class SkRegion;
     35 
     36 namespace WebCore {
     37 
     38 class FloatPoint3D;
     39 class Image;
     40 class LayerAndroid;
     41 class FixedBackgroundImageLayerAndroid;
     42 class ScrollableLayerAndroid;
     43 
     44 class GraphicsLayerAndroid : public GraphicsLayer, PicturePainter {
     45 public:
     46 
     47     GraphicsLayerAndroid(GraphicsLayerClient*);
     48     virtual ~GraphicsLayerAndroid();
     49 
     50     // PicturePainter
     51 
     52     virtual void paintContents(GraphicsContext* gc, IntRect& dirty);
     53 
     54     /////
     55 
     56     virtual void setName(const String&);
     57 
     58     // for hosting this GraphicsLayer in a native layer hierarchy
     59     virtual NativeLayer nativeLayer() const;
     60 
     61     virtual bool setChildren(const Vector<GraphicsLayer*>&);
     62     virtual void addChild(GraphicsLayer*);
     63     virtual void addChildAtIndex(GraphicsLayer*, int index);
     64     virtual void addChildAbove(GraphicsLayer* layer, GraphicsLayer* sibling);
     65     virtual void addChildBelow(GraphicsLayer* layer, GraphicsLayer* sibling);
     66     virtual bool replaceChild(GraphicsLayer* oldChild, GraphicsLayer* newChild);
     67     virtual void setReplicatedLayer(GraphicsLayer* layer);
     68 
     69     virtual void removeFromParent();
     70 
     71     virtual void setPosition(const FloatPoint&);
     72     virtual void setPreserves3D(bool b);
     73     virtual void setAnchorPoint(const FloatPoint3D&);
     74     virtual void setSize(const FloatSize&);
     75 
     76     virtual void setBackfaceVisibility(bool b);
     77     virtual void setTransform(const TransformationMatrix&);
     78 
     79     virtual void setChildrenTransform(const TransformationMatrix&);
     80 
     81     virtual void setMaskLayer(GraphicsLayer*);
     82     virtual void setMasksToBounds(bool);
     83     virtual void setDrawsContent(bool);
     84 
     85     virtual void setBackgroundColor(const Color&);
     86     virtual void clearBackgroundColor();
     87 
     88     virtual void setContentsOpaque(bool);
     89 
     90     virtual void setOpacity(float);
     91 
     92     virtual void setNeedsDisplay();
     93     virtual void setNeedsDisplayInRect(const FloatRect&);
     94 
     95     virtual bool addAnimation(const KeyframeValueList& valueList,
     96                               const IntSize& boxSize,
     97                               const Animation* anim,
     98                               const String& keyframesName,
     99                               double beginTime);
    100     bool createTransformAnimationsFromKeyframes(const KeyframeValueList&,
    101                                                 const Animation*,
    102                                                 const String& keyframesName,
    103                                                 double beginTime,
    104                                                 const IntSize& boxSize);
    105     bool createAnimationFromKeyframes(const KeyframeValueList&,
    106                                       const Animation*,
    107                                       const String& keyframesName,
    108                                       double beginTime);
    109 
    110     virtual void removeAnimationsForProperty(AnimatedPropertyID);
    111     virtual void removeAnimationsForKeyframes(const String& keyframesName);
    112     virtual void pauseAnimation(const String& keyframesName);
    113 
    114     virtual void suspendAnimations(double time);
    115     virtual void resumeAnimations();
    116 
    117     virtual void setContentsToImage(Image*);
    118     virtual void setContentsToMedia(PlatformLayer*);
    119     virtual PlatformLayer* platformLayer() const;
    120 
    121     void pauseDisplay(bool state);
    122 
    123 #ifndef NDEBUG
    124     virtual void setDebugBackgroundColor(const Color&);
    125     virtual void setDebugBorder(const Color&, float borderWidth);
    126 #endif
    127 
    128     virtual void setZPosition(float);
    129 
    130     void gatherRootLayers(Vector<const RenderLayer*>&);
    131     virtual void syncCompositingState();
    132     virtual void syncCompositingStateForThisLayerOnly();
    133     void notifyClientAnimationStarted();
    134 
    135     LayerAndroid* contentLayer() { return m_contentLayer; }
    136     LayerAndroid* foregroundLayer() { return m_foregroundLayer; }
    137 
    138     static int instancesCount();
    139 
    140     virtual void updateScrollOffset();
    141 
    142 private:
    143 
    144     void askForSync();
    145     void syncPositionState();
    146     void syncChildren();
    147     void syncMask();
    148 
    149     void updatePositionedLayers();
    150     void updateScrollingLayers();
    151     void updateFixedBackgroundLayers();
    152 
    153     // with SkPicture, we always repaint the entire layer's content.
    154     bool repaint();
    155     void needsNotifyClient();
    156 
    157     bool paintContext(LayerAndroid* layer, PicturePile& picture);
    158 
    159     bool m_needsSyncChildren;
    160     bool m_needsSyncMask;
    161     bool m_needsRepaint;
    162     bool m_needsNotifyClient;
    163 
    164     bool m_haveContents;
    165     bool m_newImage;
    166     Image* m_image;
    167 
    168     LayerAndroid* m_contentLayer;
    169     FixedBackgroundImageLayerAndroid* m_fixedBackgroundLayer;
    170     LayerAndroid* m_foregroundLayer;
    171     LayerAndroid* m_foregroundClipLayer;
    172 
    173     PicturePile m_contentLayerContent;
    174     PicturePile m_foregroundLayerContent;
    175 };
    176 
    177 } // namespace WebCore
    178 
    179 
    180 #endif // USE(ACCELERATED_COMPOSITING)
    181 
    182 #endif // GraphicsLayerAndroid_h
    183