From e93f34788b1f644f8be61a1daf6505c387e6fc3b Mon Sep 17 00:00:00 2001 From: Nicolas Roard Date: Fri, 19 Mar 2010 17:10:50 +0000 Subject: Renders fixed layers with the root canvas matrix. Fix some positioning issues. Bug:2526966 Bug:1818168 The current rendering code exposes some issues with the fact that we have fixed layers in the layers hierarchy -- parents transformations are also applied to the fixed layers, which is not what we want (fixed layers should be applied on the original canvas, with the original transform -- e.g. toolbar present or not -- but no more). One previously discussed solution was to move the fixed layers to their own hierarchy; but doing so would mean to also redo all the z-index management that we already have in the current system. The simplest way is therefore to use the original matrix (the canvas' matrix) when we have a fixed layer. The way we do this is by inserting a new LayerAndroid before the LayerAndroid root, setting the matrix of that new root to be the canvas' matrix. The drawing is then unaffected, but we can ask skia to draw using the root's matrix. The second issue solved in the CL is some positioning troubles; layers may have different dimensions than their render view, and the previous code was considering that the views were always drawn at the origin in the layer. By removing the parents layers transforms, this is not the case anymore, and we therefore need to take the render view offset into account. Finally there is some additional debug code in LayerAndroid. Change-Id: Id353ad3dfd9808252643f0e4f0140dde67480719 --- .../graphics/android/GraphicsLayerAndroid.cpp | 7 ++- WebCore/platform/graphics/android/LayerAndroid.cpp | 57 ++++++++++++++++------ WebCore/platform/graphics/android/LayerAndroid.h | 9 ++++ 3 files changed, 58 insertions(+), 15 deletions(-) (limited to 'WebCore/platform') diff --git a/WebCore/platform/graphics/android/GraphicsLayerAndroid.cpp b/WebCore/platform/graphics/android/GraphicsLayerAndroid.cpp index 7b479bf..fa4a180 100644 --- a/WebCore/platform/graphics/android/GraphicsLayerAndroid.cpp +++ b/WebCore/platform/graphics/android/GraphicsLayerAndroid.cpp @@ -250,6 +250,8 @@ void GraphicsLayerAndroid::updateFixedPosition() m_contentLayer->setFixedPosition(left, top, right, bottom, marginLeft, marginTop, marginRight, marginBottom, + offsetFromRenderer().width(), + offsetFromRenderer().height(), w, h); } } @@ -431,11 +433,14 @@ void GraphicsLayerAndroid::sendImmediateRepaint() if (rootGraphicsLayer->m_frame && rootGraphicsLayer->m_frame->view()) { + LayerAndroid* rootLayer = new LayerAndroid(true); LayerAndroid* copyLayer = new LayerAndroid(*m_contentLayer); + rootLayer->addChild(copyLayer); + copyLayer->unref(); TLOG("(%x) sendImmediateRepaint, copy the layer, (%.2f,%.2f => %.2f,%.2f)", this, m_contentLayer->getSize().width(), m_contentLayer->getSize().height(), copyLayer->getSize().width(), copyLayer->getSize().height()); - PlatformBridge::setUIRootLayer(m_frame->view(), copyLayer); + PlatformBridge::setUIRootLayer(m_frame->view(), rootLayer); PlatformBridge::immediateRepaint(m_frame->view()); } } diff --git a/WebCore/platform/graphics/android/LayerAndroid.cpp b/WebCore/platform/graphics/android/LayerAndroid.cpp index bfb086c..d6ba0a1 100644 --- a/WebCore/platform/graphics/android/LayerAndroid.cpp +++ b/WebCore/platform/graphics/android/LayerAndroid.cpp @@ -83,6 +83,7 @@ LayerAndroid::LayerAndroid(const LayerAndroid& layer) : SkLayer(layer), m_fixedMarginTop = layer.m_fixedMarginTop; m_fixedMarginRight = layer.m_fixedMarginRight; m_fixedMarginBottom = layer.m_fixedMarginBottom; + m_fixedOffset = layer.m_fixedOffset; m_fixedWidth = layer.m_fixedWidth; m_fixedHeight = layer.m_fixedHeight; @@ -249,6 +250,20 @@ const LayerAndroid* LayerAndroid::find(int x, int y) const /////////////////////////////////////////////////////////////////////////////// +// The Layer bounds and the renderview bounds are not always indentical. +// We need to compute the intersection to correctly compute the +// positiong... +static SkRect computeLayerRect(LayerAndroid* layer) { + SkRect layerRect, viewRect; + SkScalar fX, fY; + fX = layer->getOffset().fX; + fY = layer->getOffset().fY; + layerRect.set(0, 0, layer->getSize().width(), layer->getSize().height()); + viewRect.set(-fX, -fY, -fX + layer->getFixedWidth(), -fY + layer->getFixedHeight()); + layerRect.intersect(viewRect); + return layerRect; +} + void LayerAndroid::updateFixedLayersPositions(const SkRect& viewport) { if (m_isFixed) { @@ -259,15 +274,17 @@ void LayerAndroid::updateFixedLayersPositions(const SkRect& viewport) float x = dx; float y = dy; + SkRect layerRect = computeLayerRect(this); + if (m_fixedLeft.defined()) - x += m_fixedMarginLeft.calcFloatValue(w) + m_fixedLeft.calcFloatValue(w); + x += m_fixedMarginLeft.calcFloatValue(w) + m_fixedLeft.calcFloatValue(w) - layerRect.fLeft; else if (m_fixedRight.defined()) - x += w - m_fixedMarginRight.calcFloatValue(w) - m_fixedRight.calcFloatValue(w) - m_fixedWidth; + x += w - m_fixedMarginRight.calcFloatValue(w) - m_fixedRight.calcFloatValue(w) - layerRect.width(); if (m_fixedTop.defined()) - y += m_fixedMarginTop.calcFloatValue(h) + m_fixedTop.calcFloatValue(h); + y += m_fixedMarginTop.calcFloatValue(h) + m_fixedTop.calcFloatValue(h) - layerRect.fTop; else if (m_fixedBottom.defined()) - y += h - m_fixedMarginBottom.calcFloatValue(h) - m_fixedBottom.calcFloatValue(h) - m_fixedHeight; + y += h - m_fixedMarginBottom.calcFloatValue(h) - m_fixedBottom.calcFloatValue(h) - layerRect.fTop - layerRect.height(); this->setPosition(x, y); } @@ -334,6 +351,13 @@ void LayerAndroid::onDraw(SkCanvas* canvas, SkScalar opacity) { canvas->drawLine(0, h, w, h, paint); canvas->drawLine(w, h, w, 0, paint); canvas->drawLine(w, 0, 0, 0, paint); + + if (m_isFixed) { + SkRect layerRect = computeLayerRect(this); + SkPaint paint; + paint.setARGB(128, 0, 0, 255); + canvas->drawRect(layerRect, paint); + } #endif } @@ -481,6 +505,8 @@ void LayerAndroid::dumpLayers(FILE* file, int indentLevel) const writeHexVal(file, indentLevel + 1, "layer", (int)this); writeIntVal(file, indentLevel + 1, "layerId", m_uniqueId); writeIntVal(file, indentLevel + 1, "haveClip", m_haveClip); + writeIntVal(file, indentLevel + 1, "isRootLayer", m_isRootLayer); + writeIntVal(file, indentLevel + 1, "isFixed", m_isFixed); writeFloatVal(file, indentLevel + 1, "opacity", getOpacity()); writeSize(file, indentLevel + 1, "size", getSize()); @@ -492,16 +518,19 @@ void LayerAndroid::dumpLayers(FILE* file, int indentLevel) const if (m_doRotation) writeFloatVal(file, indentLevel + 1, "angle", m_angleTransform); - writeLength(file, indentLevel + 1, "fixedLeft", m_fixedLeft); - writeLength(file, indentLevel + 1, "fixedTop", m_fixedTop); - writeLength(file, indentLevel + 1, "fixedRight", m_fixedRight); - writeLength(file, indentLevel + 1, "fixedBottom", m_fixedBottom); - writeLength(file, indentLevel + 1, "fixedMarginLeft", m_fixedMarginLeft); - writeLength(file, indentLevel + 1, "fixedMarginTop", m_fixedMarginTop); - writeLength(file, indentLevel + 1, "fixedMarginRight", m_fixedMarginRight); - writeLength(file, indentLevel + 1, "fixedMarginBottom", m_fixedMarginBottom); - writeIntVal(file, indentLevel + 1, "fixedWidth", m_fixedWidth); - writeIntVal(file, indentLevel + 1, "fixedHeight", m_fixedHeight); + if (m_isFixed) { + writeLength(file, indentLevel + 1, "fixedLeft", m_fixedLeft); + writeLength(file, indentLevel + 1, "fixedTop", m_fixedTop); + writeLength(file, indentLevel + 1, "fixedRight", m_fixedRight); + writeLength(file, indentLevel + 1, "fixedBottom", m_fixedBottom); + writeLength(file, indentLevel + 1, "fixedMarginLeft", m_fixedMarginLeft); + writeLength(file, indentLevel + 1, "fixedMarginTop", m_fixedMarginTop); + writeLength(file, indentLevel + 1, "fixedMarginRight", m_fixedMarginRight); + writeLength(file, indentLevel + 1, "fixedMarginBottom", m_fixedMarginBottom); + writePoint(file, indentLevel + 1, "fixedOffset", m_fixedOffset); + writeIntVal(file, indentLevel + 1, "fixedWidth", m_fixedWidth); + writeIntVal(file, indentLevel + 1, "fixedHeight", m_fixedHeight); + } if (m_recordingPicture) { writeIntVal(file, indentLevel + 1, "picture width", m_recordingPicture->width()); diff --git a/WebCore/platform/graphics/android/LayerAndroid.h b/WebCore/platform/graphics/android/LayerAndroid.h index b92f4ac..e9416c1 100644 --- a/WebCore/platform/graphics/android/LayerAndroid.h +++ b/WebCore/platform/graphics/android/LayerAndroid.h @@ -96,6 +96,8 @@ public: SkLength marginTop, // CSS margin-top property SkLength marginRight, // CSS margin-right property SkLength marginBottom, // CSS margin-bottom property + int offsetX, // X Offset from the renderer + int offsetY, // Y Offset from the renderer int width, // visible overflow width int height) { // visible overflow height m_fixedLeft = left; @@ -106,9 +108,11 @@ public: m_fixedMarginTop = marginTop; m_fixedMarginRight = marginRight; m_fixedMarginBottom = marginBottom; + m_fixedOffset.set(offsetX, offsetY); m_fixedWidth = width; m_fixedHeight = height; m_isFixed = true; + setInheritFromRootTransform(true); } void setBackgroundColor(SkColor color); @@ -158,6 +162,10 @@ public: } void setExtra(DrawExtra* extra); // does not assign ownership int uniqueId() const { return m_uniqueId; } + bool isFixed() { return m_isFixed; } + const SkPoint& getOffset() const { return m_fixedOffset; } + int getFixedWidth() { return m_fixedWidth; } + int getFixedHeight() { return m_fixedHeight; } protected: virtual void onDraw(SkCanvas*, SkScalar opacity); @@ -185,6 +193,7 @@ private: SkLength m_fixedMarginTop; SkLength m_fixedMarginRight; SkLength m_fixedMarginBottom; + SkPoint m_fixedOffset; int m_fixedWidth; int m_fixedHeight; -- cgit v1.1