aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar reed@android.com <reed@android.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2010-02-18 19:32:03 +0000
committerGravatar reed@android.com <reed@android.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2010-02-18 19:32:03 +0000
commit81dc331e65ba5a24d515c11890234dd205408c89 (patch)
treea927ccc502d9040f7f11163e47924654dd63741c /src
parent86d4008e894f6ce0b1938ac6b45d4074af85d3b7 (diff)
update layers
git-svn-id: http://skia.googlecode.com/svn/trunk@502 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src')
-rw-r--r--src/utils/SkLayer.cpp59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/utils/SkLayer.cpp b/src/utils/SkLayer.cpp
index c5a6d9a20c..fc1f5e5ccb 100644
--- a/src/utils/SkLayer.cpp
+++ b/src/utils/SkLayer.cpp
@@ -1,4 +1,5 @@
#include "SkLayer.h"
+#include "SkCanvas.h"
SkLayer::SkLayer() {
m_doRotation = false;
@@ -15,6 +16,9 @@ SkLayer::SkLayer() {
m_scale.set(1, 1);
m_backgroundColor = 0;
+
+ fMatrix.reset();
+ fChildrenMatrix.reset();
}
SkLayer::SkLayer(const SkLayer& src) {
@@ -36,6 +40,9 @@ SkLayer::SkLayer(const SkLayer& src) {
m_fixedBottom = src.m_fixedBottom;
m_backgroundColor = src.m_backgroundColor;
+
+ fMatrix = src.fMatrix;
+ fChildrenMatrix = src.fChildrenMatrix;
}
SkLayer::~SkLayer() {
@@ -64,4 +71,56 @@ void SkLayer::removeChildren() {
m_children.reset();
}
+///////////////////////////////////////////////////////////////////////////////
+
+void SkLayer::setMatrix(const SkMatrix& matrix) {
+ fMatrix = matrix;
+}
+
+void SkLayer::setChildrenMatrix(const SkMatrix& matrix) {
+ fChildrenMatrix = matrix;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+
+void SkLayer::onSetupCanvas(SkCanvas* canvas, SkScalar, const SkRect*) {
+ SkScalar tx = m_position.fX;
+ SkScalar ty = m_position.fY;
+ canvas->translate(tx, ty);
+
+ // now apply our matrix about the anchorPoint
+ tx = SkScalarMul(m_anchorPoint.fX, m_size.width());
+ ty = SkScalarMul(m_anchorPoint.fY, m_size.height());
+ canvas->translate(tx, ty);
+ canvas->concat(this->getMatrix());
+ canvas->translate(-tx, -ty);
+}
+
+void SkLayer::onDraw(SkCanvas*, SkScalar opacity, const SkRect* viewport) {}
+
+void SkLayer::draw(SkCanvas* canvas, SkScalar opacity, const SkRect* viewport) {
+#if 0
+ SkDebugf("--- drawlayer %p anchor [%g %g] scale [%g %g]\n", this, m_anchorPoint.fX, m_anchorPoint.fY,
+ m_scale.fX, m_scale.fY);
+#endif
+
+ opacity = SkScalarMul(opacity, this->getOpacity());
+ if (opacity <= 0 || this->getSize().isEmpty()) {
+ return;
+ }
+
+ SkAutoCanvasRestore acr(canvas, false);
+ canvas->save(SkCanvas::kMatrix_SaveFlag);
+
+ this->onSetupCanvas(canvas, opacity, viewport);
+ this->onDraw(canvas, opacity, viewport);
+
+ int count = this->countChildren();
+ if (count > 0) {
+ canvas->concat(this->getChildrenMatrix());
+ for (int i = 0; i < count; i++) {
+ this->getChild(i)->draw(canvas, opacity, viewport);
+ }
+ }
+}