diff options
Diffstat (limited to 'Source/WebCore/platform/graphics/android')
9 files changed, 374 insertions, 15 deletions
diff --git a/Source/WebCore/platform/graphics/android/BaseLayerAndroid.h b/Source/WebCore/platform/graphics/android/BaseLayerAndroid.h index e6680b5..29ecf57 100644 --- a/Source/WebCore/platform/graphics/android/BaseLayerAndroid.h +++ b/Source/WebCore/platform/graphics/android/BaseLayerAndroid.h @@ -29,13 +29,13 @@ #include "Color.h" #include "GLWebViewState.h" #include "IntRect.h" +#include "Layer.h" #include "PictureSet.h" -#include "SkLayer.h" #include "SkPicture.h" namespace WebCore { -class BaseLayerAndroid : public SkLayer { +class BaseLayerAndroid : public Layer { public: BaseLayerAndroid(); diff --git a/Source/WebCore/platform/graphics/android/GraphicsLayerAndroid.cpp b/Source/WebCore/platform/graphics/android/GraphicsLayerAndroid.cpp index 992585a..fc9d85f 100644 --- a/Source/WebCore/platform/graphics/android/GraphicsLayerAndroid.cpp +++ b/Source/WebCore/platform/graphics/android/GraphicsLayerAndroid.cpp @@ -24,6 +24,7 @@ #include "FloatRect.h" #include "GraphicsContext.h" #include "Image.h" +#include "Layer.h" #include "Length.h" #include "MediaLayer.h" #include "PlatformBridge.h" @@ -34,7 +35,6 @@ #include "ScaleTransformOperation.h" #include "ScrollableLayerAndroid.h" #include "SkCanvas.h" -#include "SkLayer.h" #include "TransformationMatrix.h" #include "TranslateTransformOperation.h" diff --git a/Source/WebCore/platform/graphics/android/Layer.cpp b/Source/WebCore/platform/graphics/android/Layer.cpp new file mode 100644 index 0000000..4741397 --- /dev/null +++ b/Source/WebCore/platform/graphics/android/Layer.cpp @@ -0,0 +1,224 @@ +#include "config.h" +#include "Layer.h" +#include "SkCanvas.h" + +//#define DEBUG_DRAW_LAYER_BOUNDS +//#define DEBUG_TRACK_NEW_DELETE + +#ifdef DEBUG_TRACK_NEW_DELETE + static int gLayerAllocCount; +#endif + +/////////////////////////////////////////////////////////////////////////////// + +Layer::Layer() { + fParent = NULL; + m_opacity = SK_Scalar1; + m_size.set(0, 0); + m_position.set(0, 0); + m_anchorPoint.set(SK_ScalarHalf, SK_ScalarHalf); + + fMatrix.reset(); + fChildrenMatrix.reset(); + fFlags = 0; + +#ifdef DEBUG_TRACK_NEW_DELETE + gLayerAllocCount += 1; + SkDebugf("Layer new: %d\n", gLayerAllocCount); +#endif +} + +Layer::Layer(const Layer& src) : INHERITED() { + fParent = NULL; + m_opacity = src.m_opacity; + m_size = src.m_size; + m_position = src.m_position; + m_anchorPoint = src.m_anchorPoint; + + fMatrix = src.fMatrix; + fChildrenMatrix = src.fChildrenMatrix; + fFlags = src.fFlags; + +#ifdef DEBUG_TRACK_NEW_DELETE + gLayerAllocCount += 1; + SkDebugf("Layer copy: %d\n", gLayerAllocCount); +#endif +} + +Layer::~Layer() { + this->removeChildren(); + +#ifdef DEBUG_TRACK_NEW_DELETE + gLayerAllocCount -= 1; + SkDebugf("Layer delete: %d\n", gLayerAllocCount); +#endif +} + +/////////////////////////////////////////////////////////////////////////////// + +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(); +} + +Layer* Layer::getChild(int index) const { + if ((unsigned)index < (unsigned)m_children.count()) { + SkASSERT(m_children[index]->fParent == this); + return m_children[index]; + } + return NULL; +} + +Layer* Layer::addChild(Layer* child) { + SkASSERT(this != child); + child->ref(); + child->detachFromParent(); + SkASSERT(child->fParent == NULL); + child->fParent = this; + + *m_children.append() = child; + return child; +} + +void Layer::detachFromParent() { + if (fParent) { + int index = fParent->m_children.find(this); + SkASSERT(index >= 0); + fParent->m_children.remove(index); + fParent = NULL; + this->unref(); // this call might delete us + } +} + +void Layer::removeChildren() { + int count = m_children.count(); + for (int i = 0; i < count; i++) { + Layer* child = m_children[i]; + SkASSERT(child->fParent == this); + child->fParent = NULL; // in case it has more than one owner + child->unref(); + } + m_children.reset(); +} + +Layer* Layer::getRootLayer() const { + const Layer* root = this; + while (root->fParent != NULL) { + root = root->fParent; + } + return const_cast<Layer*>(root); +} + +/////////////////////////////////////////////////////////////////////////////// + +void Layer::getLocalTransform(SkMatrix* matrix) const { + matrix->setTranslate(m_position.fX, m_position.fY); + + 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->preTranslate(-tx, -ty); +} + +void Layer::localToGlobal(SkMatrix* matrix) const { + this->getLocalTransform(matrix); + + if (this->isInheritFromRootTransform()) { + matrix->postConcat(this->getRootLayer()->getMatrix()); + return; + } + + const Layer* layer = this; + while (layer->fParent != NULL) { + layer = layer->fParent; + + SkMatrix tmp; + layer->getLocalTransform(&tmp); + tmp.preConcat(layer->getChildrenMatrix()); + matrix->postConcat(tmp); + } +} + +/////////////////////////////////////////////////////////////////////////////// + +void Layer::onDraw(SkCanvas*, SkScalar opacity) { +// SkDebugf("----- no onDraw for %p\n", this); +} + +#include "SkString.h" + +void Layer::draw(SkCanvas* canvas, SkScalar opacity) { +#if 0 + SkString str1, str2; + // this->getMatrix().toDumpString(&str1); + // this->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(), + m_position.fX, m_position.fY, str1.c_str(), str2.c_str()); +#endif + + opacity = SkScalarMul(opacity, this->getOpacity()); + if (opacity <= 0) { +// SkDebugf("---- abort drawing %p opacity %g\n", this, opacity); + return; + } + + SkAutoCanvasRestore acr(canvas, true); + + // apply our local transform + { + SkMatrix tmp; + this->getLocalTransform(&tmp); + if (this->isInheritFromRootTransform()) { + // should we also apply the root's childrenMatrix? + canvas->setMatrix(getRootLayer()->getMatrix()); + } + canvas->concat(tmp); + } + + this->onDraw(canvas, opacity); + +#ifdef DEBUG_DRAW_LAYER_BOUNDS + { + SkRect r = SkRect::MakeSize(this->getSize()); + SkPaint p; + p.setAntiAlias(true); + p.setStyle(SkPaint::kStroke_Style); + p.setStrokeWidth(SkIntToScalar(2)); + p.setColor(0xFFFF44DD); + canvas->drawRect(r, p); + canvas->drawLine(r.fLeft, r.fTop, r.fRight, r.fBottom, p); + canvas->drawLine(r.fLeft, r.fBottom, r.fRight, r.fTop, p); + } +#endif + + int count = this->countChildren(); + if (count > 0) { + canvas->concat(this->getChildrenMatrix()); + for (int i = 0; i < count; i++) { + this->getChild(i)->draw(canvas, opacity); + } + } +} diff --git a/Source/WebCore/platform/graphics/android/Layer.h b/Source/WebCore/platform/graphics/android/Layer.h new file mode 100644 index 0000000..0e2d7d8 --- /dev/null +++ b/Source/WebCore/platform/graphics/android/Layer.h @@ -0,0 +1,135 @@ +/* + * 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 Layer_DEFINED +#define Layer_DEFINED + +#include "SkRefCnt.h" +#include "SkTDArray.h" +#include "SkColor.h" +#include "SkMatrix.h" +#include "SkPoint.h" +#include "SkRect.h" +#include "SkSize.h" + +class SkCanvas; + +class Layer : public SkRefCnt { + +public: + Layer(); + Layer(const Layer&); + virtual ~Layer(); + + bool isInheritFromRootTransform() const; + 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; } + + SkScalar getWidth() const { return m_size.width(); } + SkScalar getHeight() const { return m_size.height(); } + + void setInheritFromRootTransform(bool); + 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&); + + // children + + /** Return the number of layers in our child list. + */ + int countChildren() const; + + /** Return the child at the specified index (starting at 0). This does not + affect the reference count of the child. + */ + Layer* getChild(int index) const; + + /** Add this layer to our child list at the end (top-most), and ref() it. + If it was already in another hierarchy, remove it from that list. + Return the new child. + */ + Layer* addChild(Layer* child); + + /** Remove this layer from its parent's list (or do nothing if it has no + parent.) If it had a parent, then unref() is called. + */ + void detachFromParent(); + + /** Remove, and unref(), all of the layers in our child list. + */ + void removeChildren(); + + /** Return our parent layer, or NULL if we have none. + */ + Layer* getParent() const { return fParent; } + + /** Return the root layer in this hiearchy. If this layer is the root + (i.e. has no parent), then this returns itself. + */ + Layer* getRootLayer() const; + + // coordinate system transformations + + /** Return, in matrix, the matix transfomations that are applied locally + when this layer draws (i.e. its position and matrix/anchorPoint). + This does not include the childrenMatrix, since that is only applied + after this layer draws (but before its children draw). + */ + void getLocalTransform(SkMatrix* matrix) const; + + /** Return, in matrix, the concatenation of transforms that are applied + from this layer's root parent to the layer itself. + This is the matrix that is applied to the layer during drawing. + */ + void localToGlobal(SkMatrix* matrix) const; + + // paint method + + void draw(SkCanvas*, SkScalar opacity); + void draw(SkCanvas* canvas) { + this->draw(canvas, SK_Scalar1); + } + +protected: + virtual void onDraw(SkCanvas*, SkScalar opacity); + +private: + enum Flags { + kInheritFromRootTransform_Flag = 0x01 + }; + + Layer* fParent; + SkScalar m_opacity; + SkSize m_size; + SkPoint m_position; + SkPoint m_anchorPoint; + SkMatrix fMatrix; + SkMatrix fChildrenMatrix; + uint32_t fFlags; + + SkTDArray<Layer*> m_children; + + typedef SkRefCnt INHERITED; +}; + +#endif diff --git a/Source/WebCore/platform/graphics/android/LayerAndroid.cpp b/Source/WebCore/platform/graphics/android/LayerAndroid.cpp index e90829a..cfbbd0d 100644 --- a/Source/WebCore/platform/graphics/android/LayerAndroid.cpp +++ b/Source/WebCore/platform/graphics/android/LayerAndroid.cpp @@ -54,7 +54,7 @@ class OpacityDrawFilter : public SkDrawFilter { /////////////////////////////////////////////////////////////////////////////// -LayerAndroid::LayerAndroid(RenderLayer* owner) : SkLayer(), +LayerAndroid::LayerAndroid(RenderLayer* owner) : Layer(), m_haveClip(false), m_isFixed(false), m_isIframe(false), @@ -84,7 +84,7 @@ LayerAndroid::LayerAndroid(RenderLayer* owner) : SkLayer(), #endif } -LayerAndroid::LayerAndroid(const LayerAndroid& layer) : SkLayer(layer), +LayerAndroid::LayerAndroid(const LayerAndroid& layer) : Layer(layer), m_haveClip(layer.m_haveClip), m_isIframe(layer.m_isIframe), m_contentsImage(0), @@ -139,7 +139,7 @@ LayerAndroid::LayerAndroid(const LayerAndroid& layer) : SkLayer(layer), #endif } -LayerAndroid::LayerAndroid(SkPicture* picture) : SkLayer(), +LayerAndroid::LayerAndroid(SkPicture* picture) : Layer(), m_haveClip(false), m_isFixed(false), m_isIframe(false), diff --git a/Source/WebCore/platform/graphics/android/LayerAndroid.h b/Source/WebCore/platform/graphics/android/LayerAndroid.h index 551e020..9dfe973 100644 --- a/Source/WebCore/platform/graphics/android/LayerAndroid.h +++ b/Source/WebCore/platform/graphics/android/LayerAndroid.h @@ -23,10 +23,10 @@ #include "FloatPoint3D.h" #include "FloatRect.h" #include "GraphicsLayerClient.h" +#include "Layer.h" #include "LayerTexture.h" #include "RefPtr.h" #include "SkColor.h" -#include "SkLayer.h" #include "TextureOwner.h" #include "TransformationMatrix.h" @@ -89,7 +89,7 @@ class LayerAndroidFindState; class RenderLayer; class TiledPage; -class LayerAndroid : public SkLayer, public TextureOwner { +class LayerAndroid : public Layer, public TextureOwner { public: LayerAndroid(RenderLayer* owner); @@ -371,7 +371,7 @@ private: RenderLayer* m_owningLayer; - typedef SkLayer INHERITED; + typedef Layer INHERITED; }; } diff --git a/Source/WebCore/platform/graphics/android/PaintLayerOperation.cpp b/Source/WebCore/platform/graphics/android/PaintLayerOperation.cpp index 35867c7..c1ac865 100644 --- a/Source/WebCore/platform/graphics/android/PaintLayerOperation.cpp +++ b/Source/WebCore/platform/graphics/android/PaintLayerOperation.cpp @@ -42,7 +42,7 @@ void PaintLayerOperation::run() m_layer->paintBitmapGL(); } -SkLayer* PaintLayerOperation::baseLayer() +Layer* PaintLayerOperation::baseLayer() { if (!m_layer) return 0; diff --git a/Source/WebCore/platform/graphics/android/PaintLayerOperation.h b/Source/WebCore/platform/graphics/android/PaintLayerOperation.h index 74e87af..e688d87 100644 --- a/Source/WebCore/platform/graphics/android/PaintLayerOperation.h +++ b/Source/WebCore/platform/graphics/android/PaintLayerOperation.h @@ -28,7 +28,7 @@ #include "QueuedOperation.h" -class SkLayer; +class Layer; namespace WebCore { @@ -43,7 +43,7 @@ class PaintLayerOperation : public QueuedOperation { virtual ~PaintLayerOperation() {} virtual bool operator==(const QueuedOperation* operation); virtual void run(); - SkLayer* baseLayer(); + Layer* baseLayer(); LayerAndroid* layer() { return m_layer; } LayerTexture* texture(); @@ -53,11 +53,11 @@ class PaintLayerOperation : public QueuedOperation { class PaintLayerBaseFilter : public OperationFilter { public: - PaintLayerBaseFilter(SkLayer* layer) : m_baseLayer(layer) {} + PaintLayerBaseFilter(Layer* layer) : m_baseLayer(layer) {} virtual bool check(QueuedOperation* operation); private: - SkLayer* m_baseLayer; + Layer* m_baseLayer; }; class PaintLayerTextureFilter : public OperationFilter { diff --git a/Source/WebCore/platform/graphics/android/TilesManager.cpp b/Source/WebCore/platform/graphics/android/TilesManager.cpp index b4df0a1..10e47ee 100644 --- a/Source/WebCore/platform/graphics/android/TilesManager.cpp +++ b/Source/WebCore/platform/graphics/android/TilesManager.cpp @@ -272,7 +272,7 @@ void TilesManager::printLayersTextures(const char* s) void TilesManager::cleanupLayersTextures(LayerAndroid* layer, bool forceCleanup) { android::Mutex::Autolock lock(m_texturesLock); - SkLayer* rootLayer = 0; + Layer* rootLayer = 0; if (layer) rootLayer = layer->getRootLayer(); #ifdef DEBUG |