From be24d84c76bb32c72d597fce1c9de599ced95565 Mon Sep 17 00:00:00 2001 From: Mike Reed Date: Fri, 12 Feb 2010 14:56:12 +0000 Subject: [PATCH] move children into SkLayer make SkLayer inherit from SkRefCnt.h --- .../graphics/android/GraphicsLayerAndroid.cpp | 11 +- .../graphics/android/GraphicsLayerAndroid.h | 4 +- WebCore/platform/graphics/android/LayerAndroid.cpp | 45 +++---- WebCore/platform/graphics/android/LayerAndroid.h | 10 +- WebCore/platform/graphics/android/SkLayer.h | 144 --------------------- 5 files changed, 30 insertions(+), 184 deletions(-) delete mode 100644 WebCore/platform/graphics/android/SkLayer.h diff --git a/WebCore/platform/graphics/android/GraphicsLayerAndroid.cpp b/WebCore/platform/graphics/android/GraphicsLayerAndroid.cpp index b1662f42b..9470bb94f 100644 --- a/WebCore/platform/graphics/android/GraphicsLayerAndroid.cpp +++ b/WebCore/platform/graphics/android/GraphicsLayerAndroid.cpp @@ -121,7 +121,7 @@ GraphicsLayerAndroid::GraphicsLayerAndroid(GraphicsLayerClient* client) : m_currentTranslateY(0), m_currentPosition(0, 0) { - m_contentLayer = adoptRef(new LayerAndroid(true)); + m_contentLayer = new LayerAndroid(true); if (client) { RenderLayerBacking* backing = static_cast(client); RenderLayer* renderLayer = backing->owningLayer(); @@ -141,6 +141,7 @@ GraphicsLayerAndroid::GraphicsLayerAndroid(GraphicsLayerClient* client) : GraphicsLayerAndroid::~GraphicsLayerAndroid() { + m_contentLayer->unref(); gDebugGraphicsLayerAndroidInstances--; } @@ -406,7 +407,7 @@ void GraphicsLayerAndroid::sendImmediateRepaint() if (rootGraphicsLayer->m_frame && rootGraphicsLayer->m_frame->view()) { - LayerAndroid* copyLayer = new LayerAndroid(m_contentLayer.get()); + LayerAndroid* copyLayer = new LayerAndroid(*m_contentLayer); TLOG("(%x) sendImmediateRepaint, copy the layer, (%.2f,%.2f => %.2f,%.2f)", this, m_contentLayer->size().width(), m_contentLayer->size().height(), copyLayer->size().width(), copyLayer->size().height()); @@ -801,7 +802,7 @@ void GraphicsLayerAndroid::setContentsToImage(Image* image) PlatformLayer* GraphicsLayerAndroid::platformLayer() const { LOG("platformLayer"); - return (PlatformLayer*) m_contentLayer.get(); + return (PlatformLayer*) m_contentLayer; } #ifndef NDEBUG @@ -830,9 +831,9 @@ void GraphicsLayerAndroid::askForSync() void GraphicsLayerAndroid::syncChildren() { if (m_needsSyncChildren) { - m_contentLayer->removeAllChildren(); + m_contentLayer->removeChildren(); for (unsigned int i = 0; i < m_children.size(); i++) { - m_contentLayer->addChildren( + m_contentLayer->addChild( (static_cast(m_children[i]))->contentLayer()); } m_needsSyncChildren = false; diff --git a/WebCore/platform/graphics/android/GraphicsLayerAndroid.h b/WebCore/platform/graphics/android/GraphicsLayerAndroid.h index 591a2612b..8c8058685 100644 --- a/WebCore/platform/graphics/android/GraphicsLayerAndroid.h +++ b/WebCore/platform/graphics/android/GraphicsLayerAndroid.h @@ -119,7 +119,7 @@ public: void notifyClientAnimationStarted(); void sendImmediateRepaint(); - LayerAndroid* contentLayer() { return m_contentLayer.get(); } + LayerAndroid* contentLayer() { return m_contentLayer; } static int instancesCount(); @@ -148,7 +148,7 @@ private: Vector m_invalidatedRects; - RefPtr m_contentLayer; + LayerAndroid* m_contentLayer; }; } // namespace WebCore diff --git a/WebCore/platform/graphics/android/LayerAndroid.cpp b/WebCore/platform/graphics/android/LayerAndroid.cpp index 14b9a965e..52a457d2d 100644 --- a/WebCore/platform/graphics/android/LayerAndroid.cpp +++ b/WebCore/platform/graphics/android/LayerAndroid.cpp @@ -43,11 +43,6 @@ class OpacityDrawFilter : public SkDrawFilter { int m_previousOpacity; }; -PassRefPtr LayerAndroid::create(bool isRootLayer) -{ - return adoptRef(new LayerAndroid(isRootLayer)); -} - LayerAndroid::LayerAndroid(bool isRootLayer) : SkLayer(), m_isRootLayer(isRootLayer), m_haveContents(false), @@ -59,21 +54,21 @@ LayerAndroid::LayerAndroid(bool isRootLayer) : SkLayer(), gDebugLayerAndroidInstances++; } -LayerAndroid::LayerAndroid(LayerAndroid* layer) : SkLayer(layer), - m_isRootLayer(layer->m_isRootLayer), - m_haveContents(layer->m_haveContents), - m_drawsContent(layer->m_drawsContent), - m_haveImage(layer->m_haveImage), - m_haveClip(layer->m_haveClip) +LayerAndroid::LayerAndroid(const LayerAndroid& layer) : SkLayer(layer), + m_isRootLayer(layer.m_isRootLayer), + m_haveContents(layer.m_haveContents), + m_drawsContent(layer.m_drawsContent), + m_haveImage(layer.m_haveImage), + m_haveClip(layer.m_haveClip) { - m_recordingPicture = layer->m_recordingPicture; + 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()))); + for (int i = 0; i < layer.countChildren(); i++) + addChild(new LayerAndroid(*static_cast(layer.getChild(i))))->unref(); - KeyframesMap::const_iterator end = layer->m_animations.end(); - for (KeyframesMap::const_iterator it = layer->m_animations.begin(); it != end; ++it) + KeyframesMap::const_iterator end = layer.m_animations.end(); + for (KeyframesMap::const_iterator it = layer.m_animations.begin(); it != end; ++it) m_animations.add((it->second)->name(), (it->second)->copy()); gDebugLayerAndroidInstances++; @@ -81,8 +76,8 @@ LayerAndroid::LayerAndroid(LayerAndroid* layer) : SkLayer(layer), LayerAndroid::~LayerAndroid() { + removeChildren(); m_recordingPicture->safeUnref(); - m_children.clear(); m_animations.clear(); gDebugLayerAndroidInstances--; } @@ -98,8 +93,8 @@ bool LayerAndroid::evaluateAnimations() const bool LayerAndroid::hasAnimations() const { - for (unsigned int i = 0; i < m_children.size(); i++) { - if (m_children[i]->hasAnimations()) + for (int i = 0; i < countChildren(); i++) { + if (static_cast(getChild(i))->hasAnimations()) return true; } return !!m_animations.size(); @@ -108,8 +103,8 @@ bool LayerAndroid::hasAnimations() const bool LayerAndroid::evaluateAnimations(double time) const { bool hasRunningAnimations = false; - for (unsigned int i = 0; i < m_children.size(); i++) { - if (m_children[i]->evaluateAnimations(time)) + for (int i = 0; i < countChildren(); i++) { + if (static_cast(getChild(i))->evaluateAnimations(time)) hasRunningAnimations = true; } KeyframesMap::const_iterator end = m_animations.end(); @@ -137,8 +132,8 @@ void LayerAndroid::removeAnimation(const String& name) void LayerAndroid::setDrawsContent(bool drawsContent) { m_drawsContent = drawsContent; - for (unsigned int i = 0; i < m_children.size(); i++) { - LayerAndroid* layer = m_children[i].get(); + for (int i = 0; i < countChildren(); i++) { + LayerAndroid* layer = static_cast(getChild(i)); layer->setDrawsContent(drawsContent); } } @@ -209,8 +204,8 @@ void LayerAndroid::paintChildren(int scrollX, int scrollY, 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(); + for (int i = 0; i < countChildren(); i++) { + LayerAndroid* layer = static_cast(getChild(i)); if (layer) { gDebugChildLevel++; layer->paintChildren(scrollX, scrollY, width, height, scale, diff --git a/WebCore/platform/graphics/android/LayerAndroid.h b/WebCore/platform/graphics/android/LayerAndroid.h index 911a2f9e1..e6dbfb998 100644 --- a/WebCore/platform/graphics/android/LayerAndroid.h +++ b/WebCore/platform/graphics/android/LayerAndroid.h @@ -39,12 +39,11 @@ namespace WebCore { class AndroidAnimation; class AndroidAnimationValue; -class LayerAndroid : public SkLayer, public RefCounted { +class LayerAndroid : public SkLayer { public: - static PassRefPtr create(bool isRootLayer); LayerAndroid(bool isRootLayer); - LayerAndroid(LayerAndroid* layer); + LayerAndroid(const LayerAndroid& layer); virtual ~LayerAndroid(); static int instancesCount(); @@ -59,8 +58,6 @@ public: 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); void startRecording(); void stopRecording(); @@ -77,8 +74,6 @@ public: float scale, float* xPtr, float* yPtr); SkPicture* picture() const { return m_recordingPicture; } - const LayerAndroid* child(unsigned i) const { return m_children[i].get(); } - unsigned childCount() const { return m_children.size(); } private: @@ -100,7 +95,6 @@ private: SkPicture* m_recordingPicture; - Vector > m_children; typedef HashMap > KeyframesMap; KeyframesMap m_animations; }; diff --git a/WebCore/platform/graphics/android/SkLayer.h b/WebCore/platform/graphics/android/SkLayer.h deleted file mode 100644 index 3e6f4d28d..000000000 --- a/WebCore/platform/graphics/android/SkLayer.h +++ /dev/null @@ -1,144 +0,0 @@ -/* - * 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() const { - 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() const { return m_position; } - SkPoint translation() const { return m_translation; } - SkSize size() const { return m_size; } - SkRect bounds() const { - SkRect rect; - rect.set(m_position.fX, m_position.fY, - m_position.fX + m_size.width(), - m_position.fY + m_size.height()); - rect.offset(m_translation.fX, m_translation.fY); - return rect; - } - - // 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 m_children; -}; - -#endif -- 2.11.0