From 297e0a10e071c3389212e4be467e4833bc3717ef Mon Sep 17 00:00:00 2001 From: John Reck Date: Fri, 20 Jul 2012 14:20:57 -0700 Subject: Fix bounds for shadows Change-Id: I304c6e78e9e570dd4e67fa101697ca3b2f17acd7 --- .../context/PlatformGraphicsContextRecording.cpp | 29 +++++++++++++++++++--- .../context/PlatformGraphicsContextRecording.h | 1 + 2 files changed, 26 insertions(+), 4 deletions(-) (limited to 'Source/WebCore') diff --git a/Source/WebCore/platform/graphics/android/context/PlatformGraphicsContextRecording.cpp b/Source/WebCore/platform/graphics/android/context/PlatformGraphicsContextRecording.cpp index f11154d..6b9d27f 100644 --- a/Source/WebCore/platform/graphics/android/context/PlatformGraphicsContextRecording.cpp +++ b/Source/WebCore/platform/graphics/android/context/PlatformGraphicsContextRecording.cpp @@ -596,6 +596,28 @@ void PlatformGraphicsContextRecording::popMatrix() mCurrentMatrix = &(mMatrixStack.last()); } +IntRect PlatformGraphicsContextRecording::calculateFinalBounds(FloatRect bounds) +{ + if (m_gc->hasShadow()) { + const ShadowRec& shadow = m_state->shadow; + if (shadow.blur > 0) + bounds.inflate(ceilf(shadow.blur)); + bounds.setWidth(bounds.width() + abs(shadow.dx)); + bounds.setHeight(bounds.height() + abs(shadow.dy)); + if (shadow.dx < 0) + bounds.move(shadow.dx, 0); + if (shadow.dy < 0) + bounds.move(0, shadow.dy); + // Add a bit extra to deal with rounding and blurring + bounds.inflate(4); + } + if (m_state->strokeStyle != NoStroke) + bounds.inflate(std::min(1.0f, m_state->strokeThickness)); + SkRect translated; + mCurrentMatrix->mapRect(&translated, bounds); + return enclosingIntRect(translated); +} + void PlatformGraphicsContextRecording::appendDrawingOperation( GraphicsOperation::Operation* operation, const FloatRect& untranslatedBounds) { @@ -604,12 +626,11 @@ void PlatformGraphicsContextRecording::appendDrawingOperation( return; } m_isEmpty = false; - SkRect bounds; - mCurrentMatrix->mapRect(&bounds, untranslatedBounds); if (mRecordingStateStack.size()) { RecordingState& state = mRecordingStateStack.last(); state.mHasDrawing = true; - state.addBounds(bounds); + if (!state.mHasClip) + state.addBounds(calculateFinalBounds(untranslatedBounds)); state.mSaveOperation->operations()->adoptAndAppend(operation); return; } @@ -621,7 +642,7 @@ void PlatformGraphicsContextRecording::appendDrawingOperation( operation->m_matrix = mOperationMatrix; RecordingData* data = new RecordingData(operation, mRecording->recording()->m_nodeCount++); - WebCore::IntRect ibounds = enclosingIntRect(bounds); + WebCore::IntRect ibounds = calculateFinalBounds(untranslatedBounds); mRecording->recording()->m_tree.insert(ibounds, data); } diff --git a/Source/WebCore/platform/graphics/android/context/PlatformGraphicsContextRecording.h b/Source/WebCore/platform/graphics/android/context/PlatformGraphicsContextRecording.h index 89f9bbb..fd6fb5e 100644 --- a/Source/WebCore/platform/graphics/android/context/PlatformGraphicsContextRecording.h +++ b/Source/WebCore/platform/graphics/android/context/PlatformGraphicsContextRecording.h @@ -152,6 +152,7 @@ private: void popSaveOperation(); void pushMatrix(); void popMatrix(); + IntRect calculateFinalBounds(FloatRect bounds); SkPicture* mPicture; SkMatrix* mCurrentMatrix; -- cgit v1.1