OSDN Git Service

Clean up style and add some comments in Layer
authorSteve Block <steveblock@google.com>
Wed, 21 Sep 2011 14:36:17 +0000 (15:36 +0100)
committerSteve Block <steveblock@google.com>
Wed, 21 Sep 2011 14:43:06 +0000 (15:43 +0100)
This is preparation for https://android-git.corp.google.com/g/#/c/134488/4

Refactoring only, no functional change.

Bug: 5262656
Change-Id: I44e362cf35fc5080f7d9fba34183188d3a2a6331

Source/WebCore/platform/graphics/android/Layer.cpp
Source/WebCore/platform/graphics/android/Layer.h
Source/WebCore/platform/graphics/android/LayerAndroid.h
Source/WebKit/android/jni/ViewStateSerializer.cpp

index 22c40f1..361cb4e 100644 (file)
@@ -18,9 +18,9 @@ Layer::Layer() {
     m_position.set(0, 0);
     m_anchorPoint.set(SK_ScalarHalf, SK_ScalarHalf);
 
-    fMatrix.reset();
-    fChildrenMatrix.reset();
-    fFlags = 0;
+    m_matrix.reset();
+    m_childrenMatrix.reset();
+    m_shouldInheritFromRootTransform = false;
 
     m_hasOverflowChildren = false;
 
@@ -37,9 +37,9 @@ Layer::Layer(const Layer& src) : INHERITED() {
     m_position = src.m_position;
     m_anchorPoint = src.m_anchorPoint;
 
-    fMatrix = src.fMatrix;
-    fChildrenMatrix = src.fChildrenMatrix;
-    fFlags = src.fFlags;
+    m_matrix = src.m_matrix;
+    m_childrenMatrix = src.m_childrenMatrix;
+    m_shouldInheritFromRootTransform = src.m_shouldInheritFromRootTransform;
 
     m_hasOverflowChildren = src.m_hasOverflowChildren;
 
@@ -50,7 +50,7 @@ Layer::Layer(const Layer& src) : INHERITED() {
 }
 
 Layer::~Layer() {
-    this->removeChildren();
+    removeChildren();
 
 #ifdef DEBUG_TRACK_NEW_DELETE
     gLayerAllocCount -= 1;
@@ -60,28 +60,6 @@ Layer::~Layer() {
 
 ///////////////////////////////////////////////////////////////////////////////
 
-bool Layer::isInheritFromRootTransform() const {
-    return (fFlags & kInheritFromRootTransform_Flag) != 0;
-}
-
-void Layer::setInheritFromRootTransform(bool doInherit) {
-    if (doInherit) {
-        fFlags |= kInheritFromRootTransform_Flag;
-    } else {
-        fFlags &= ~kInheritFromRootTransform_Flag;
-    }
-}
-
-void Layer::setMatrix(const SkMatrix& matrix) {
-    fMatrix = matrix;
-}
-
-void Layer::setChildrenMatrix(const SkMatrix& matrix) {
-    fChildrenMatrix = matrix;
-}
-
-///////////////////////////////////////////////////////////////////////////////
-
 int Layer::countChildren() const {
     return m_children.count();
 }
@@ -111,7 +89,7 @@ void Layer::detachFromParent() {
         SkASSERT(index >= 0);
         fParent->m_children.remove(index);
         fParent = NULL;
-        this->unref();  // this call might delete us
+        unref();  // this call might delete us
     }
 }
 
@@ -142,15 +120,15 @@ void Layer::getLocalTransform(SkMatrix* matrix) const {
     SkScalar tx = SkScalarMul(m_anchorPoint.fX, m_size.width());
     SkScalar ty = SkScalarMul(m_anchorPoint.fY, m_size.height());
     matrix->preTranslate(tx, ty);
-    matrix->preConcat(this->getMatrix());
+    matrix->preConcat(getMatrix());
     matrix->preTranslate(-tx, -ty);
 }
 
 void Layer::localToGlobal(SkMatrix* matrix) const {
-    this->getLocalTransform(matrix);
+    getLocalTransform(matrix);
 
-    if (this->isInheritFromRootTransform()) {
-        matrix->postConcat(this->getRootLayer()->getMatrix());
+    if (shouldInheritFromRootTransform()) {
+        matrix->postConcat(getRootLayer()->getMatrix());
         return;
     }
 
@@ -176,14 +154,14 @@ void Layer::onDraw(SkCanvas*, SkScalar opacity) {
 void Layer::draw(SkCanvas* canvas, SkScalar opacity) {
 #if 0
     SkString str1, str2;
- //   this->getMatrix().toDumpString(&str1);
- //   this->getChildrenMatrix().toDumpString(&str2);
+ //   getMatrix().toDumpString(&str1);
+ //   getChildrenMatrix().toDumpString(&str2);
     SkDebugf("--- drawlayer %p opacity %g size [%g %g] pos [%g %g] matrix %s children %s\n",
-             this, opacity * this->getOpacity(), m_size.width(), m_size.height(),
+             this, opacity * getOpacity(), m_size.width(), m_size.height(),
              m_position.fX, m_position.fY, str1.c_str(), str2.c_str());
 #endif
 
-    opacity = SkScalarMul(opacity, this->getOpacity());
+    opacity = SkScalarMul(opacity, getOpacity());
     if (opacity <= 0) {
 //        SkDebugf("---- abort drawing %p opacity %g\n", this, opacity);
         return;
@@ -194,19 +172,19 @@ void Layer::draw(SkCanvas* canvas, SkScalar opacity) {
     // apply our local transform
     {
         SkMatrix tmp;
-        this->getLocalTransform(&tmp);
-        if (this->isInheritFromRootTransform()) {
+        getLocalTransform(&tmp);
+        if (shouldInheritFromRootTransform()) {
             // should we also apply the root's childrenMatrix?
             canvas->setMatrix(getRootLayer()->getMatrix());
         }
         canvas->concat(tmp);
     }
 
-    this->onDraw(canvas, opacity);
+    onDraw(canvas, opacity);
 
 #ifdef DEBUG_DRAW_LAYER_BOUNDS
     {
-        SkRect r = SkRect::MakeSize(this->getSize());
+        SkRect r = SkRect::MakeSize(getSize());
         SkPaint p;
         p.setAntiAlias(true);
         p.setStyle(SkPaint::kStroke_Style);
@@ -218,11 +196,11 @@ void Layer::draw(SkCanvas* canvas, SkScalar opacity) {
     }
 #endif
 
-    int count = this->countChildren();
+    int count = countChildren();
     if (count > 0) {
-        canvas->concat(this->getChildrenMatrix());
+        canvas->concat(getChildrenMatrix());
         for (int i = 0; i < count; i++) {
-            this->getChild(i)->draw(canvas, opacity);
+            getChild(i)->draw(canvas, opacity);
         }
     }
 }
index 107c457..7b27349 100644 (file)
@@ -34,24 +34,27 @@ public:
     Layer(const Layer&);
     virtual ~Layer();
 
-    bool isInheritFromRootTransform() const;
+    // Whether the layer should apply its tranform directly onto the root
+    // layer, rather than using the transforms of all ancestor layers. This is
+    // used for fixed position layers.
+    bool shouldInheritFromRootTransform() const { return m_shouldInheritFromRootTransform; }
     SkScalar getOpacity() const { return m_opacity; }
     const SkSize& getSize() const { return m_size; }
     const SkPoint& getPosition() const { return m_position; }
     const SkPoint& getAnchorPoint() const { return m_anchorPoint; }
-    const SkMatrix& getMatrix() const { return fMatrix; }
-    const SkMatrix& getChildrenMatrix() const { return fChildrenMatrix; }
+    const SkMatrix& getMatrix() const { return m_matrix; }
+    const SkMatrix& getChildrenMatrix() const { return m_childrenMatrix; }
 
     SkScalar getWidth() const { return m_size.width(); }
     SkScalar getHeight() const { return m_size.height(); }
 
-    void setInheritFromRootTransform(bool);
+    void setShouldInheritFromRootTransform(bool inherit) { m_shouldInheritFromRootTransform = inherit; }
     void setOpacity(SkScalar opacity) { m_opacity = opacity; }
     void setSize(SkScalar w, SkScalar h) { m_size.set(w, h); }
     void setPosition(SkScalar x, SkScalar y) { m_position.set(x, y); }
     void setAnchorPoint(SkScalar x, SkScalar y) { m_anchorPoint.set(x, y); }
-    void setMatrix(const SkMatrix&);
-    void setChildrenMatrix(const SkMatrix&);
+    void setMatrix(const SkMatrix& matrix) { m_matrix = matrix; }
+    void setChildrenMatrix(const SkMatrix& matrix) { m_childrenMatrix = matrix; }
 
     // children
 
@@ -118,10 +121,6 @@ protected:
     bool m_hasOverflowChildren;
 
 private:
-    enum Flags {
-        kInheritFromRootTransform_Flag = 0x01
-    };
-
     Layer* fParent;
     SkScalar m_opacity;
     SkSize m_size;
@@ -130,9 +129,9 @@ private:
     // The point in the layer used as the origin for local transformations,
     // expressed as a fraction of the layer size.
     SkPoint m_anchorPoint;
-    SkMatrix fMatrix;
-    SkMatrix fChildrenMatrix;
-    uint32_t fFlags;
+    SkMatrix m_matrix;
+    SkMatrix m_childrenMatrix;
+    bool m_shouldInheritFromRootTransform;
 
     SkTDArray<Layer*> m_children;
 
index 8078762..31bb185 100644 (file)
@@ -170,7 +170,7 @@ public:
         m_fixedRect = viewRect;
         m_isFixed = true;
         m_renderLayerPos = renderLayerPos;
-        setInheritFromRootTransform(true);
+        setShouldInheritFromRootTransform(true);
     }
 
     void setBackgroundColor(SkColor color);
index 794c118..b3556c3 100644 (file)
@@ -257,7 +257,7 @@ void serializeLayer(LayerAndroid* layer, SkWStream* stream)
     stream->write8(type);
 
     // Start with Layer fields
-    stream->writeBool(layer->isInheritFromRootTransform());
+    stream->writeBool(layer->shouldInheritFromRootTransform());
     stream->writeScalar(layer->getOpacity());
     stream->writeScalar(layer->getSize().width());
     stream->writeScalar(layer->getSize().height());
@@ -338,7 +338,7 @@ LayerAndroid* deserializeLayer(SkStream* stream)
     }
 
     // Layer fields
-    layer->setInheritFromRootTransform(stream->readBool());
+    layer->setShouldInheritFromRootTransform(stream->readBool());
     layer->setOpacity(stream->readScalar());
     layer->setSize(stream->readScalar(), stream->readScalar());
     layer->setPosition(stream->readScalar(), stream->readScalar());