diff options
author | Mike Reed <reed@google.com> | 2010-02-19 11:32:42 -0500 |
---|---|---|
committer | Mike Reed <reed@google.com> | 2010-02-19 15:20:01 -0500 |
commit | cdd7f6d80774ba3a374f09f22f7cb6bcfca24fa5 (patch) | |
tree | 47712f26b3db7e9df23e9382cff9e48b15dca352 /WebCore/platform | |
parent | be4ea5d07252747b3faad9dd63d4bebe79f24db3 (diff) | |
download | external_webkit-cdd7f6d80774ba3a374f09f22f7cb6bcfca24fa5.zip external_webkit-cdd7f6d80774ba3a374f09f22f7cb6bcfca24fa5.tar.gz external_webkit-cdd7f6d80774ba3a374f09f22f7cb6bcfca24fa5.tar.bz2 |
move viewport into just this subclass
Diffstat (limited to 'WebCore/platform')
-rw-r--r-- | WebCore/platform/graphics/android/GraphicsLayerAndroid.cpp | 4 | ||||
-rw-r--r-- | WebCore/platform/graphics/android/LayerAndroid.cpp | 212 | ||||
-rw-r--r-- | WebCore/platform/graphics/android/LayerAndroid.h | 91 |
3 files changed, 139 insertions, 168 deletions
diff --git a/WebCore/platform/graphics/android/GraphicsLayerAndroid.cpp b/WebCore/platform/graphics/android/GraphicsLayerAndroid.cpp index 7f6ffe4..ee7c888 100644 --- a/WebCore/platform/graphics/android/GraphicsLayerAndroid.cpp +++ b/WebCore/platform/graphics/android/GraphicsLayerAndroid.cpp @@ -450,8 +450,8 @@ bool GraphicsLayerAndroid::repaint(const FloatRect& rect) // with SkPicture, we request the entire layer's content. r.setX(0); r.setY(0); - r.setWidth(m_contentLayer->size().width()); - r.setHeight(m_contentLayer->size().height()); + r.setWidth(m_contentLayer->getWidth()); + r.setHeight(m_contentLayer->getHeight()); paintGraphicsLayerContents(gc, r); TLOG("(%x) repaint(%.2f,%.2f,%.2f,%.2f) on (%.2f,%.2f) contentlayer(%.2f,%.2f,%.2f,%.2f)paintGraphicsLayer called!", diff --git a/WebCore/platform/graphics/android/LayerAndroid.cpp b/WebCore/platform/graphics/android/LayerAndroid.cpp index 0561731..9d60efd 100644 --- a/WebCore/platform/graphics/android/LayerAndroid.cpp +++ b/WebCore/platform/graphics/android/LayerAndroid.cpp @@ -39,16 +39,25 @@ class OpacityDrawFilter : public SkDrawFilter { int m_previousOpacity; }; +/////////////////////////////////////////////////////////////////////////////// + LayerAndroid::LayerAndroid(bool isRootLayer) : SkLayer(), m_isRootLayer(isRootLayer), m_haveContents(false), m_drawsContent(true), m_haveImage(false), m_haveClip(false), + m_doRotation(false), + m_isFixed(false), m_recordingPicture(0), m_findOnPage(0), m_uniqueId(++gUniqueId) { + m_angleTransform = 0; + m_translation.set(0, 0); + m_scale.set(1, 1); + m_backgroundColor = 0; + gDebugLayerAndroidInstances++; } @@ -61,6 +70,19 @@ LayerAndroid::LayerAndroid(const LayerAndroid& layer) : SkLayer(layer), m_findOnPage(0), m_uniqueId(layer.m_uniqueId) { + m_doRotation = layer.m_doRotation; + m_isFixed = layer.m_isFixed; + + m_angleTransform = layer.m_angleTransform; + m_translation = layer.m_translation; + m_scale = layer.m_scale; + m_backgroundColor = layer.m_backgroundColor; + + m_fixedLeft = layer.m_fixedLeft; + m_fixedTop = layer.m_fixedTop; + m_fixedRight = layer.m_fixedRight; + m_fixedBottom = layer.m_fixedBottom; + m_recordingPicture = layer.m_recordingPicture; SkSafeRef(m_recordingPicture); @@ -152,7 +174,6 @@ void LayerAndroid::setMasksToBounds(bool masksToBounds) void LayerAndroid::setBackgroundColor(SkColor color) { m_backgroundColor = color; - m_backgroundColorSet = true; setHaveContents(true); setDrawsContent(true); } @@ -161,10 +182,12 @@ static int gDebugChildLevel; void LayerAndroid::bounds(SkRect* rect) const { - rect->fLeft = m_position.fX + m_translation.fX; - rect->fTop = m_position.fY + m_translation.fY; - rect->fRight = rect->fLeft + m_size.width(); - rect->fBottom = rect->fTop + m_size.height(); + const SkPoint& pos = this->getPosition(); + const SkSize& size = this->getSize(); + rect->fLeft = pos.fX + m_translation.fX; + rect->fTop = pos.fY + m_translation.fY; + rect->fRight = rect->fLeft + size.width(); + rect->fBottom = rect->fTop + size.height(); } bool LayerAndroid::boundsIsUnique(SkTDArray<SkRect>* region, @@ -220,105 +243,70 @@ void LayerAndroid::setClip(SkCanvas* canvas) canvas->clipRect(clip); } -void LayerAndroid::paintChildren(const SkRect* viewPort, SkCanvas* canvas, - float opacity) -{ - int count = canvas->save(); - - if (m_haveClip) - setClip(canvas); - - paintMe(viewPort, canvas, opacity); - canvas->translate(m_position.fX + m_translation.fX, - m_position.fY + m_translation.fY); +/////////////////////////////////////////////////////////////////////////////// - for (int i = 0; i < countChildren(); i++) { - gDebugChildLevel++; - getChild(i)->paintChildren(viewPort, canvas, opacity * m_opacity); - gDebugChildLevel--; - } - - canvas->restoreToCount(count); -} - -void LayerAndroid::updatePosition(const SkRect& viewPort) { +void LayerAndroid::updatePositions(const SkRect& viewport) { + // apply the viewport to us + SkMatrix matrix; if (m_isFixed) { float x = 0; float y = 0; - float w = viewPort.width(); - float h = viewPort.height(); - float dx = viewPort.fLeft; - float dy = viewPort.fTop; - - if (m_fixedLeft.defined()) - x = dx + m_fixedLeft.calcFloatValue(w); - else if (m_fixedRight.defined()) - x = dx + w - m_fixedRight.calcFloatValue(w) - m_size.width(); - - if (m_fixedTop.defined()) - y = dy + m_fixedTop.calcFloatValue(h); - else if (m_fixedBottom.defined()) - y = dy + h - m_fixedBottom.calcFloatValue(h) - m_size.height(); - - this->setPosition(x, y); - } -} - -bool LayerAndroid::calcPosition(SkCanvas* canvas, const SkRect* viewPort) { - if (viewPort && m_isFixed) { - float x = 0; - float y = 0; - float w = viewPort->width(); - float h = viewPort->height(); - float dx = viewPort->fLeft; - float dy = viewPort->fTop; + float w = viewport.width(); + float h = viewport.height(); + float dx = viewport.fLeft; + float dy = viewport.fTop; if (m_fixedLeft.defined()) x = dx + m_fixedLeft.calcFloatValue(w); else if (m_fixedRight.defined()) - x = dx + w - m_fixedRight.calcFloatValue(w) - m_size.width(); + x = dx + w - m_fixedRight.calcFloatValue(w) - getSize().width(); if (m_fixedTop.defined()) y = dy + m_fixedTop.calcFloatValue(h); else if (m_fixedBottom.defined()) - y = dy + h - m_fixedBottom.calcFloatValue(h) - m_size.height(); + y = dy + h - m_fixedBottom.calcFloatValue(h) - getSize().height(); this->setPosition(x, y); - canvas->translate(x, y); - return true; - } - return false; -} - -void LayerAndroid::onSetupCanvas(SkCanvas* canvas, SkScalar opacity, - const SkRect* viewport) { - if (!this->calcPosition(canvas, viewport)) { - SkMatrix matrix; + matrix.reset(); + } else { + // turn our fields into a matrix. + // + // TODO: this should happen in the caller, and we should remove these + // fields from our subclass matrix.setTranslate(m_translation.fX, m_translation.fY); if (m_doRotation) { matrix.preRotate(m_angleTransform); } matrix.preScale(m_scale.fX, m_scale.fY); - this->setMatrix(matrix); - - this->INHERITED::onSetupCanvas(canvas, opacity, viewport); } + this->setMatrix(matrix); + + // now apply it to our children + int count = this->countChildren(); + if (count > 0) { + SkRect tmp = viewport; + // adjust the viewport by our (the parent) position + tmp.offset(-this->getPosition()); + for (int i = 0; i < count; i++) { + this->getChild(i)->updatePositions(tmp); + } + } +} +void LayerAndroid::onDraw(SkCanvas* canvas, SkScalar opacity) { if (m_haveClip) { SkRect r; r.set(0, 0, getSize().width(), getSize().height()); canvas->clipRect(r); } -} -void LayerAndroid::onDraw(SkCanvas* canvas, SkScalar opacity, - const SkRect* viewport) { if (!prepareContext()) return; if (!m_haveImage && !m_drawsContent && !m_isRootLayer) return; + // we just have this save/restore for opacity... SkAutoCanvasRestore restore(canvas, true); int canvasOpacity = SkScalarRound(opacity * 255); @@ -328,76 +316,6 @@ void LayerAndroid::onDraw(SkCanvas* canvas, SkScalar opacity, m_recordingPicture->draw(canvas); } -void LayerAndroid::paintMe(const SkRect* viewPort, - SkCanvas* canvas, - float opacity) -{ - if (!prepareContext()) - return; - - if (!m_haveImage && !m_drawsContent && !m_isRootLayer) - return; - - SkAutoCanvasRestore restore(canvas, true); - - int canvasOpacity = opacity * m_opacity * 255; - if (canvasOpacity != 255) - canvas->setDrawFilter(new OpacityDrawFilter(canvasOpacity)); - - /* FIXME - SkPaint paintMode; - if (m_backgroundColorSet) { - paintMode.setColor(m_backgroundColor); - } else - paintMode.setARGB(0, 0, 0, 0); - - paintMode.setXfermodeMode(SkXfermode::kSrc_Mode); - */ - - float x, y; - if (!calcPosition(canvas, viewPort)) { - SkMatrix matrix; - matrix.reset(); - if (m_doRotation) { - float anchorX = m_anchorPoint.fX * m_size.width(); - float anchorY = m_anchorPoint.fY * m_size.height(); - matrix.preTranslate(anchorX, anchorY); - matrix.preRotate(m_angleTransform); - matrix.preTranslate(-anchorX, -anchorY); - } - - 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(); - matrix.preTranslate(-dx / 2.0f, -dy / 2.0f); - matrix.preScale(sx, sy); - } - matrix.postTranslate(m_translation.fX + m_position.fX, - m_translation.fY + m_position.fY); - canvas->concat(matrix); - } - - m_recordingPicture->draw(canvas); - - if (m_findOnPage) - m_findOnPage->drawLayer(canvas, 0, m_uniqueId); -#ifdef LAYER_DEBUG - float w = m_size.width(); - float h = m_size.height(); - SkPaint paint; - paint.setARGB(128, 255, 0, 0); - canvas->drawLine(0, 0, w, h, paint); - canvas->drawLine(0, h, w, 0, paint); - paint.setARGB(128, 0, 255, 0); - canvas->drawLine(0, 0, 0, h, paint); - canvas->drawLine(0, h, w, h, paint); - canvas->drawLine(w, h, w, 0, paint); - canvas->drawLine(w, 0, 0, 0, paint); -#endif -} - SkPicture* LayerAndroid::recordContext() { if (prepareContext(true)) @@ -413,8 +331,8 @@ bool LayerAndroid::prepareContext(bool force) if (!m_isRootLayer) { if (force || !m_recordingPicture || (m_recordingPicture - && ((m_recordingPicture->width() != (int) m_size.width()) - || (m_recordingPicture->height() != (int) m_size.height())))) { + && ((m_recordingPicture->width() != (int) getSize().width()) + || (m_recordingPicture->height() != (int) getSize().height())))) { m_recordingPicture->safeUnref(); m_recordingPicture = new SkPicture(); } @@ -509,11 +427,11 @@ void LayerAndroid::dumpLayers(FILE* file, int indentLevel) const writeIntVal(file, indentLevel + 1, "haveImage", m_haveImage); writeIntVal(file, indentLevel + 1, "clipRect", m_haveClip); - writeFloatVal(file, indentLevel + 1, "opacity", m_opacity); - writeSize(file, indentLevel + 1, "size", m_size); - writePoint(file, indentLevel + 1, "position", m_position); + writeFloatVal(file, indentLevel + 1, "opacity", getOpacity()); + writeSize(file, indentLevel + 1, "size", getSize()); + writePoint(file, indentLevel + 1, "position", getPosition()); writePoint(file, indentLevel + 1, "translation", m_translation); - writePoint(file, indentLevel + 1, "anchor", m_anchorPoint); + writePoint(file, indentLevel + 1, "anchor", getAnchorPoint()); writePoint(file, indentLevel + 1, "scale", m_scale); if (m_doRotation) diff --git a/WebCore/platform/graphics/android/LayerAndroid.h b/WebCore/platform/graphics/android/LayerAndroid.h index 9037dc5..d3f2357 100644 --- a/WebCore/platform/graphics/android/LayerAndroid.h +++ b/WebCore/platform/graphics/android/LayerAndroid.h @@ -30,6 +30,31 @@ class SkCanvas; class SkMatrix; 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; + } + } +}; + namespace WebCore { class AndroidAnimation; @@ -43,16 +68,37 @@ public: static int instancesCount(); + 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); } + SkPoint translation() const { return m_translation; } + SkRect bounds() const { + const SkPoint& pos = this->getPosition(); + const SkSize& size = this->getSize(); + SkRect rect; + rect.set(pos.fX, pos.fY, + pos.fX + size.width(), + pos.fY + size.height()); + rect.offset(m_translation.fX, m_translation.fY); + return rect; + } + 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; + } + + void setBackgroundColor(SkColor color); void setHaveContents(bool haveContents) { m_haveContents = haveContents; } void setHaveImage(bool haveImage) { m_haveImage = haveImage; } void setDrawsContent(bool drawsContent); void setFindOnPage(FindOnPage* findOnPage); void setMaskLayer(LayerAndroid*); void setMasksToBounds(bool); - virtual void setBackgroundColor(SkColor color); void setIsRootLayer(bool isRootLayer) { m_isRootLayer = isRootLayer; } -// virtual void draw(SkCanvas*, SkScalar opacity, const SkRect* viewPort); bool prepareContext(bool force = false); void startRecording(); void stopRecording(); @@ -69,42 +115,49 @@ public: void dumpLayers(FILE*, int indentLevel) const; - void bounds(SkRect* ) const; /** Call this with the current viewport (scrolling, zoom) to update its position attribute, so that later calls like bounds() will report the corrected position (assuming the layer had fixed-positioning). + + This call is recursive, so it should be called on the root of the + hierarchy. */ - void updatePosition(const SkRect& viewPort); + void updatePositions(const SkRect& viewPort); + + void bounds(SkRect* ) const; void clipArea(SkTDArray<SkRect>* region) const; const LayerAndroid* find(int x, int y) const; const LayerAndroid* findById(int uniqueID) const; - LayerAndroid* getChild(int index) const { return - static_cast<LayerAndroid*>(m_children[index]); } + LayerAndroid* getChild(int index) const { + return static_cast<LayerAndroid*>(this->INHERITED::getChild(index)); + } bool haveClip() const { return m_haveClip; } int uniqueId() const { return m_uniqueId; } -private: - bool boundsIsUnique(SkTDArray<SkRect>* region, const SkRect& local) const; - void clipInner(SkTDArray<SkRect>* region, const SkRect& local) const; protected: - virtual void onSetupCanvas(SkCanvas*, SkScalar opacity, const SkRect*); - virtual void onDraw(SkCanvas*, SkScalar opacity, const SkRect* viewPort); + virtual void onDraw(SkCanvas*, SkScalar opacity); private: - - bool calcPosition(SkCanvas*, const SkRect* viewPort); - - void paintChildren(const SkRect* viewPort, SkCanvas* canvas, - float opacity); - - void paintMe(const SkRect* viewPort, SkCanvas* canvas, - float opacity); + bool boundsIsUnique(SkTDArray<SkRect>* region, const SkRect& local) const; + void clipInner(SkTDArray<SkRect>* region, const SkRect& local) const; bool m_isRootLayer; bool m_haveContents; bool m_drawsContent; bool m_haveImage; bool m_haveClip; + bool m_doRotation; + bool m_isFixed; + bool m_backgroundColorSet; + + SkLength m_fixedLeft; + SkLength m_fixedTop; + SkLength m_fixedRight; + SkLength m_fixedBottom; + SkPoint m_translation; + SkPoint m_scale; + SkScalar m_angleTransform; + SkColor m_backgroundColor; SkPicture* m_recordingPicture; |