diff options
author | Nicolas Roard <nicolas@android.com> | 2010-02-11 17:40:33 +0000 |
---|---|---|
committer | Nicolas Roard <nicolas@android.com> | 2010-02-11 17:48:07 +0000 |
commit | ba1ed26a6f245f68ba76318d7ec9451fb0886922 (patch) | |
tree | 6556a773f073d0979b1ea2f9cb739f68ca414a70 /WebCore/platform | |
parent | e8ae13df7065e0f00876ae8edc7e67a2483068a7 (diff) | |
download | external_webkit-ba1ed26a6f245f68ba76318d7ec9451fb0886922.zip external_webkit-ba1ed26a6f245f68ba76318d7ec9451fb0886922.tar.gz external_webkit-ba1ed26a6f245f68ba76318d7ec9451fb0886922.tar.bz2 |
Layers refactoring
Diffstat (limited to 'WebCore/platform')
-rw-r--r-- | WebCore/platform/graphics/android/AndroidAnimation.cpp | 4 | ||||
-rw-r--r-- | WebCore/platform/graphics/android/GraphicsLayerAndroid.cpp | 50 | ||||
-rw-r--r-- | WebCore/platform/graphics/android/LayerAndroid.cpp | 111 | ||||
-rw-r--r-- | WebCore/platform/graphics/android/LayerAndroid.h | 37 | ||||
-rw-r--r-- | WebCore/platform/graphics/android/SkLayer.h | 136 |
5 files changed, 223 insertions, 115 deletions
diff --git a/WebCore/platform/graphics/android/AndroidAnimation.cpp b/WebCore/platform/graphics/android/AndroidAnimation.cpp index 5ea8d2a..ca1acbe 100644 --- a/WebCore/platform/graphics/android/AndroidAnimation.cpp +++ b/WebCore/platform/graphics/android/AndroidAnimation.cpp @@ -33,10 +33,10 @@ namespace WebCore { void AndroidTransformAnimationValue::apply() { if (m_doTranslation) - m_layer->setTranslation(m_translation); + m_layer->setTranslation(m_translation.x(), m_translation.y()); if (m_doScaling) - m_layer->setScale(m_scale); + m_layer->setScale(m_scale.x(), m_scale.y()); if (m_doRotation) m_layer->setRotation(m_rotation); diff --git a/WebCore/platform/graphics/android/GraphicsLayerAndroid.cpp b/WebCore/platform/graphics/android/GraphicsLayerAndroid.cpp index bcfe13d..b1662f4 100644 --- a/WebCore/platform/graphics/android/GraphicsLayerAndroid.cpp +++ b/WebCore/platform/graphics/android/GraphicsLayerAndroid.cpp @@ -25,6 +25,8 @@ #include "FloatRect.h" #include "GraphicsContext.h" #include "Image.h" +#include "Length.h" +#include "SkLayer.h" #include "PlatformBridge.h" #include "PlatformGraphicsContext.h" #include "RenderLayerBacking.h" @@ -90,6 +92,20 @@ PassOwnPtr<GraphicsLayer> GraphicsLayer::create(GraphicsLayerClient* client) return new GraphicsLayerAndroid(client); } +SkLength convertLength(Length l) { + SkLength length; + length.type = SkLength::Undefined; + length.value = 0; + if (l.type() == WebCore::Percent) { + length.type = SkLength::Percent; + length.value = l.percent(); + } if (l.type() == WebCore::Fixed) { + length.type = SkLength::Fixed; + length.value = l.value(); + } + return length; +} + GraphicsLayerAndroid::GraphicsLayerAndroid(GraphicsLayerClient* client) : GraphicsLayer(client), m_needsSyncChildren(false), @@ -107,16 +123,18 @@ GraphicsLayerAndroid::GraphicsLayerAndroid(GraphicsLayerClient* client) : { m_contentLayer = adoptRef(new LayerAndroid(true)); if (client) { - RenderLayerBacking* backing = static_cast<RenderLayerBacking*>(client); - RenderLayer* renderLayer = backing->owningLayer(); - m_contentLayer->setIsRootLayer(renderLayer->isRootLayer()); - RenderView* view = static_cast<RenderView*>(renderLayer->renderer()); - if (view->isPositioned() && view->style()->position() == FixedPosition) { - m_contentLayer->setFixedPosition(view->style()->left(), - view->style()->top(), - view->style()->right(), - view->style()->bottom()); - } + RenderLayerBacking* backing = static_cast<RenderLayerBacking*>(client); + RenderLayer* renderLayer = backing->owningLayer(); + m_contentLayer->setIsRootLayer(renderLayer->isRootLayer()); + RenderView* view = static_cast<RenderView*>(renderLayer->renderer()); + if (view->isPositioned() && view->style()->position() == FixedPosition) { + SkLength left, top, right, bottom; + left = convertLength(view->style()->left()); + top = convertLength(view->style()->top()); + right = convertLength(view->style()->right()); + bottom = convertLength(view->style()->bottom()); + m_contentLayer->setFixedPosition(left, top, right, bottom); + } } gDebugGraphicsLayerAndroidInstances++; } @@ -223,7 +241,7 @@ void GraphicsLayerAndroid::setPosition(const FloatPoint& point) void GraphicsLayerAndroid::setAnchorPoint(const FloatPoint3D& point) { GraphicsLayer::setAnchorPoint(point); - m_contentLayer->setAnchorPoint(point); + m_contentLayer->setAnchorPoint(point.x(), point.y()); askForSync(); } @@ -233,7 +251,7 @@ void GraphicsLayerAndroid::setSize(const FloatSize& size) || (size.height() != m_size.height())) { MLOG("(%x) setSize (%.2f,%.2f)", this, size.width(), size.height()); GraphicsLayer::setSize(size); - m_contentLayer->setSize(size); + m_contentLayer->setSize(size.width(), size.height()); askForSync(); } } @@ -305,7 +323,8 @@ void GraphicsLayerAndroid::setBackgroundColor(const Color& color) { LOG("(%x) setBackgroundColor", this); GraphicsLayer::setBackgroundColor(color); - m_contentLayer->setBackgroundColor(color); + SkColor c = SkColorSetARGB(color.alpha(), color.red(), color.green(), color.blue()); + m_contentLayer->setBackgroundColor(c); m_haveContents = true; askForSync(); } @@ -841,9 +860,8 @@ void GraphicsLayerAndroid::syncPositionState() m_translateX = m_currentTranslateX; m_translateY = m_currentTranslateY; m_position = m_currentPosition; - FloatPoint translation(m_currentTranslateX, m_currentTranslateY); - m_contentLayer->setTranslation(translation); - m_contentLayer->setPosition(m_currentPosition); + m_contentLayer->setTranslation(m_currentTranslateX, m_currentTranslateY); + m_contentLayer->setPosition(m_currentPosition.x(), m_currentPosition.y()); m_needsDisplay = false; } } diff --git a/WebCore/platform/graphics/android/LayerAndroid.cpp b/WebCore/platform/graphics/android/LayerAndroid.cpp index e080d3d..f741370 100644 --- a/WebCore/platform/graphics/android/LayerAndroid.cpp +++ b/WebCore/platform/graphics/android/LayerAndroid.cpp @@ -17,6 +17,12 @@ #define LAYER_DEBUG // Add diagonals for debugging #undef LAYER_DEBUG +#include <cutils/log.h> +#include <wtf/CurrentTime.h> + +#undef LOG +#define LOG(...) android_printLog(ANDROID_LOG_DEBUG, "LayerAndroid", __VA_ARGS__) + namespace WebCore { static int gDebugLayerAndroidInstances; @@ -48,57 +54,26 @@ PassRefPtr<LayerAndroid> LayerAndroid::create(bool isRootLayer) return adoptRef(new LayerAndroid(isRootLayer)); } -LayerAndroid::LayerAndroid(bool isRootLayer) : - m_doRotation(false), +LayerAndroid::LayerAndroid(bool isRootLayer) : SkLayer(), m_isRootLayer(isRootLayer), - m_isFixed(false), m_haveContents(false), m_drawsContent(true), m_haveImage(false), m_haveClip(false), - m_backgroundColorSet(false), - m_angleTransform(0), - m_opacity(1), - m_size(0, 0), - m_position(0, 0), - m_translation(0, 0), - m_anchorPoint(0, 0, 0), - m_scale(1, 1, 1), - m_fixedLeft(Auto), - m_fixedTop(Auto), - m_fixedRight(Auto), - m_fixedBottom(Auto), m_recordingPicture(0) { gDebugLayerAndroidInstances++; } -LayerAndroid::LayerAndroid(LayerAndroid* layer) : - m_doRotation(layer->m_doRotation), +LayerAndroid::LayerAndroid(LayerAndroid* layer) : SkLayer(layer), m_isRootLayer(layer->m_isRootLayer), - m_isFixed(layer->m_isFixed), m_haveContents(layer->m_haveContents), m_drawsContent(layer->m_drawsContent), m_haveImage(layer->m_haveImage), - m_haveClip(layer->m_haveClip), - m_backgroundColorSet(layer->m_backgroundColorSet), - m_angleTransform(layer->m_angleTransform), - m_opacity(layer->m_opacity), - m_size(layer->m_size), - m_position(layer->m_position), - m_translation(layer->m_translation), - m_anchorPoint(layer->m_anchorPoint), - m_scale(layer->m_scale), - m_fixedLeft(layer->m_fixedLeft), - m_fixedTop(layer->m_fixedTop), - m_fixedRight(layer->m_fixedRight), - m_fixedBottom(layer->m_fixedBottom) + m_haveClip(layer->m_haveClip) { - if (layer->m_recordingPicture) { - layer->m_recordingPicture->ref(); - m_recordingPicture = layer->m_recordingPicture; - } else - m_recordingPicture = 0; + m_recordingPicture = layer->m_recordingPicture; + SkSafeRef(m_recordingPicture); for (unsigned int i = 0; i < layer->m_children.size(); i++) m_children.append(adoptRef(new LayerAndroid(layer->m_children[i].get()))); @@ -173,16 +148,6 @@ void LayerAndroid::removeAnimation(const String& name) m_animations.remove(name); } -void LayerAndroid::setFixedPosition(Length left, Length top, - Length right, Length bottom) -{ - m_fixedLeft = left; - m_fixedTop = top; - m_fixedRight = right; - m_fixedBottom = bottom; - m_isFixed = true; -} - void LayerAndroid::setDrawsContent(bool drawsContent) { m_drawsContent = drawsContent; @@ -205,7 +170,7 @@ void LayerAndroid::setMasksToBounds(bool masksToBounds) m_haveClip = masksToBounds; } -void LayerAndroid::setBackgroundColor(const Color& color) +void LayerAndroid::setBackgroundColor(SkColor color) { m_backgroundColor = color; m_backgroundColorSet = true; @@ -219,15 +184,27 @@ void LayerAndroid::paintOn(int scrollX, int scrollY, int width, int height, float scale, SkCanvas* canvas) { + SkSize size; + size.set(width, height); + paintOn(SkPoint::Make(scrollX, scrollY), size, scale, canvas); +} + +void LayerAndroid::paintOn(SkPoint offset, SkSize size, SkScalar scale, SkCanvas* canvas) +{ gDebugChildLevel = 0; + int scrollX = offset.fX; + int scrollY = offset.fY; + int width = size.width(); + int height = size.height(); + LOG("(%x) PaintOn (scroll(%d,%d) width(%d) height(%d)", this, scrollX, scrollY, width, height); paintChildren(scrollX, scrollY, width, height, scale, canvas, 1); } void LayerAndroid::setClip(SkCanvas* canvas) { SkRect clip; - clip.fLeft = m_position.x() + m_translation.x(); - clip.fTop = m_position.y() + m_translation.y(); + clip.fLeft = m_position.fX + m_translation.fX; + clip.fTop = m_position.fY + m_translation.fY; clip.fRight = clip.fLeft + m_size.width(); clip.fBottom = clip.fTop + m_size.height(); canvas->clipRect(clip); @@ -244,8 +221,8 @@ void LayerAndroid::paintChildren(int scrollX, int scrollY, setClip(canvas); paintMe(scrollX, scrollY, width, height, scale, canvas, opacity); - canvas->translate(m_position.x() + m_translation.x(), - m_position.y() + m_translation.y()); + canvas->translate(m_position.fX + m_translation.fX, + m_position.fY + m_translation.fY); for (unsigned int i = 0; i < m_children.size(); i++) { LayerAndroid* layer = m_children[i].get(); @@ -268,6 +245,8 @@ void LayerAndroid::paintMe(int scrollX, SkCanvas* canvas, float opacity) { + LOG("(%x) A - paint me (width: %.2f height: %.2f), anchor(%.2f, %.2f), translate(%.2f, %.2f), position(%.2f, %.2f) angle(%.2f) fixed(%d) rotation(%d)", + this, m_size.width(), m_size.height(), m_anchorPoint.fX, m_anchorPoint.fY, m_translation.fX, m_translation.fY, m_position.fX, m_position.fY, m_angleTransform, m_isFixed, m_doRotation); if (!prepareContext()) return; @@ -280,16 +259,15 @@ void LayerAndroid::paintMe(int scrollX, if (canvasOpacity != 255) canvas->setDrawFilter(new OpacityDrawFilter(canvasOpacity)); + /* FIXME SkPaint paintMode; if (m_backgroundColorSet) { - paintMode.setARGB(m_backgroundColor.alpha(), - m_backgroundColor.red(), - m_backgroundColor.green(), - m_backgroundColor.blue()); + paintMode.setColor(m_backgroundColor); } else paintMode.setARGB(0, 0, 0, 0); paintMode.setXfermodeMode(SkXfermode::kSrc_Mode); + */ float x = 0; float y = 0; @@ -299,33 +277,33 @@ void LayerAndroid::paintMe(int scrollX, float dx = scrollX / scale; float dy = scrollY / scale; - if (m_fixedLeft.type()) + if (m_fixedLeft.defined()) x = dx + m_fixedLeft.calcFloatValue(w); - else if (m_fixedRight.type()) + else if (m_fixedRight.defined()) x = dx + w - m_fixedRight.calcFloatValue(w) - m_size.width(); - if (m_fixedTop.type()) + if (m_fixedTop.defined()) y = dy + m_fixedTop.calcFloatValue(h); - else if (m_fixedBottom.type()) + else if (m_fixedBottom.defined()) y = dy + h - m_fixedBottom.calcFloatValue(h) - m_size.height(); } else { - x = m_translation.x() + m_position.x(); - y = m_translation.y() + m_position.y(); + x = m_translation.fX + m_position.fX; + y = m_translation.fY + m_position.fY; } canvas->translate(x, y); if (m_doRotation) { - float anchorX = m_anchorPoint.x() * m_size.width(); - float anchorY = m_anchorPoint.y() * m_size.height(); + float anchorX = m_anchorPoint.fX * m_size.width(); + float anchorY = m_anchorPoint.fY * m_size.height(); canvas->translate(anchorX, anchorY); canvas->rotate(m_angleTransform); canvas->translate(-anchorX, -anchorY); } - float sx = m_scale.x(); - float sy = m_scale.y(); + float sx = m_scale.fX; + float sy = m_scale.fY; if (sx > 1.0f || sy > 1.0f) { float dx = (sx * m_size.width()) - m_size.width(); float dy = (sy * m_size.height()) - m_size.height(); @@ -333,6 +311,9 @@ void LayerAndroid::paintMe(int scrollX, canvas->scale(sx, sy); } + LOG("(%x) B - paint me (width: %.2f height: %.2f) with x(%.2f) y(%.2f), scale (%.2f, %.2f), anchor(%.2f, %.2f), translate(%.2f, %.2f), position(%.2f, %.2f) angle(%.2f) fixed(%d) rotation(%d)", + this, m_size.width(), m_size.height(), x, y, sx, sy, m_anchorPoint.fX, m_anchorPoint.fY, m_translation.fX, m_translation.fY, m_position.fX, m_position.fY, m_angleTransform, m_isFixed, m_doRotation); + m_recordingPicture->draw(canvas); #ifdef LAYER_DEBUG diff --git a/WebCore/platform/graphics/android/LayerAndroid.h b/WebCore/platform/graphics/android/LayerAndroid.h index 6ca4083..480521b 100644 --- a/WebCore/platform/graphics/android/LayerAndroid.h +++ b/WebCore/platform/graphics/android/LayerAndroid.h @@ -25,6 +25,7 @@ #include "FloatSize.h" #include "Length.h" #include "RefPtr.h" +#include "SkLayer.h" #include "StringHash.h" #include "Vector.h" #include <wtf/HashMap.h> @@ -38,32 +39,26 @@ namespace WebCore { class AndroidAnimation; class AndroidAnimationValue; -class LayerAndroid : public RefCounted<LayerAndroid> { +class LayerAndroid : public SkLayer, public RefCounted<LayerAndroid> { public: static PassRefPtr<LayerAndroid> create(bool isRootLayer); LayerAndroid(bool isRootLayer); LayerAndroid(LayerAndroid* layer); - ~LayerAndroid(); + virtual ~LayerAndroid(); static int instancesCount(); - void setSize(FloatSize size) { m_size = size; } - void setOpacity(float opacity) { m_opacity = opacity; } - void setTranslation(FloatPoint translation) { m_translation = translation; } - void setRotation(float a) { m_angleTransform = a; m_doRotation = true; } - void setScale(FloatPoint3D scale) { m_scale = scale; } - void setPosition(FloatPoint position) { m_position = position; } - void setAnchorPoint(FloatPoint3D point) { m_anchorPoint = point; } void setHaveContents(bool haveContents) { m_haveContents = haveContents; } void setHaveImage(bool haveImage) { m_haveImage = haveImage; } void setDrawsContent(bool drawsContent); void setMaskLayer(LayerAndroid*); void setMasksToBounds(bool); - void setBackgroundColor(const Color& color); + virtual void setBackgroundColor(SkColor color); void setIsRootLayer(bool isRootLayer) { m_isRootLayer = isRootLayer; } void paintOn(int scrollX, int scrollY, int width, int height, float scale, SkCanvas*); + void paintOn(SkPoint offset, SkSize size, SkScalar scale, SkCanvas*); void removeAllChildren() { m_children.clear(); } void addChildren(LayerAndroid* layer) { m_children.append(layer); } bool prepareContext(bool force = false); @@ -71,11 +66,7 @@ public: void stopRecording(); SkPicture* recordContext(); void setClip(SkCanvas* clip); - FloatPoint position() { return m_position; } - FloatPoint translation() { return m_translation; } - FloatSize size() { return m_size; } - void setFixedPosition(Length left, Length top, Length right, Length bottom); void addAnimation(PassRefPtr<AndroidAnimation> anim); void removeAnimation(const String& name); Vector<RefPtr<AndroidAnimationValue> >* evaluateAnimations() const; @@ -95,31 +86,13 @@ private: float scale, SkCanvas* canvas, float opacity); - bool m_doRotation; bool m_isRootLayer; - bool m_isFixed; bool m_haveContents; bool m_drawsContent; bool m_haveImage; bool m_haveClip; - bool m_backgroundColorSet; - - float m_angleTransform; - float m_opacity; - - FloatSize m_size; - FloatPoint m_position; - FloatPoint m_translation; - FloatPoint3D m_anchorPoint; - FloatPoint3D m_scale; - - Length m_fixedLeft; - Length m_fixedTop; - Length m_fixedRight; - Length m_fixedBottom; SkPicture* m_recordingPicture; - Color m_backgroundColor; Vector<RefPtr<LayerAndroid> > m_children; typedef HashMap<String, RefPtr<AndroidAnimation> > KeyframesMap; diff --git a/WebCore/platform/graphics/android/SkLayer.h b/WebCore/platform/graphics/android/SkLayer.h new file mode 100644 index 0000000..39f04f4 --- /dev/null +++ b/WebCore/platform/graphics/android/SkLayer.h @@ -0,0 +1,136 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef SkLayer_h +#define SkLayer_h + +#include "SkCanvas.h" +#include "SkRefCnt.h" +#include "SkTDArray.h" +#include "SkColor.h" +#include "SkPoint.h" +#include "SkSize.h" + +class SkPicture; + + +struct SkLength { + enum SkLengthType { Undefined, Auto, Relative, Percent, Fixed, Static, Intrinsic, MinIntrinsic }; + SkLengthType type; + SkScalar value; + SkLength() { + type = Undefined; + value = 0; + } + bool defined() { + if (type == Undefined) + return false; + return true; + } + float calcFloatValue(float max) const { + switch (type) { + case Percent: + return (max * value) / 100.0f; + case Fixed: + return value; + default: + return value; + } + } +}; + +class SkLayer /*: public SkRefCnt*/ { + +public: + SkLayer() { + m_doRotation = false; + m_isFixed = false; + m_backgroundColorSet = false; + m_angleTransform = 0; + m_opacity = 1; + m_size.set(0, 0); + m_translation.set(0, 0); + m_anchorPoint.set(0.5, 0.5); + m_scale.set(1, 1); + } + + SkLayer(SkLayer* layer) { + memcpy(this, layer, sizeof(*this)); + } + + virtual ~SkLayer() {}; + + // setters + + void setSize(SkScalar w, SkScalar h) { m_size.set(w, h); } + void setOpacity(SkScalar opacity) { m_opacity = opacity; } + void setTranslation(SkScalar x, SkScalar y) { m_translation.set(x, y); } + void setRotation(SkScalar a) { m_angleTransform = a; m_doRotation = true; } + void setScale(SkScalar x, SkScalar y) { m_scale.set(x, y); } + void setPosition(SkScalar x, SkScalar y) { m_position.set(x, y); } + void setAnchorPoint(SkScalar x, SkScalar y) { m_anchorPoint.set(x, y); } + virtual void setBackgroundColor(SkColor color) { m_backgroundColor = color; m_backgroundColorSet = true; } + void setFixedPosition(SkLength left, SkLength top, SkLength right, SkLength bottom) { + m_fixedLeft = left; + m_fixedTop = top; + m_fixedRight = right; + m_fixedBottom = bottom; + m_isFixed = true; + } + + // getters + + SkPoint position() { return m_position; } + SkPoint translation() { return m_translation; } + SkSize size() { return m_size; } + + // paint method + + virtual void paintOn(SkPoint offset, SkSize size, SkScalar scale, SkCanvas*) = 0; + + // children manipulation + +// void removeAllChildren(); +// void addChildren(LayerAndroid* layer); + +public: + + bool m_doRotation; + bool m_isFixed; + bool m_backgroundColorSet; + + // layers properties + + SkScalar m_angleTransform; + SkScalar m_opacity; + + SkSize m_size; + SkPoint m_position; + SkPoint m_translation; + SkPoint m_anchorPoint; + SkPoint m_scale; + + SkLength m_fixedLeft; + SkLength m_fixedTop; + SkLength m_fixedRight; + SkLength m_fixedBottom; + + SkColor m_backgroundColor; + +// SkTDArray<SkLayer*> m_children; +}; + +#endif |