From cd037d9094659dcb6f998997d7f32e99fc6b7697 Mon Sep 17 00:00:00 2001 From: John Reck Date: Tue, 26 Jun 2012 11:50:07 -0700 Subject: Filter out empty save/restores WebKit will sometimes produce graphics context calls that result in GC::Save, GC::SetClip, GC::Restore - as they don't do any drawing, we can detect and filter those out which saves on the amount of state management done. Change-Id: I61715b0a14adb39521c605e2562fc4ac4e70a327 --- .../context/GraphicsOperationCollection.cpp | 60 +++++++++++++++++++++- .../android/context/GraphicsOperationCollection.h | 3 ++ 2 files changed, 61 insertions(+), 2 deletions(-) (limited to 'Source/WebCore/platform') diff --git a/Source/WebCore/platform/graphics/android/context/GraphicsOperationCollection.cpp b/Source/WebCore/platform/graphics/android/context/GraphicsOperationCollection.cpp index 03a0d8f..c5be59f 100644 --- a/Source/WebCore/platform/graphics/android/context/GraphicsOperationCollection.cpp +++ b/Source/WebCore/platform/graphics/android/context/GraphicsOperationCollection.cpp @@ -13,6 +13,31 @@ namespace WebCore { +using namespace GraphicsOperation; + +static bool isDrawingOperation(GraphicsOperation::Operation* operation) { + switch (operation->type()) { + case Operation::DrawBitmapPatternOperation: + case Operation::DrawBitmapRectOperation: + case Operation::DrawEllipseOperation: + case Operation::DrawLineOperation: + case Operation::DrawLineForTextOperation: + case Operation::DrawLineForTextCheckingOperation: + case Operation::DrawRectOperation: + case Operation::FillPathOperation: + case Operation::FillRectOperation: + case Operation::FillRoundedRectOperation: + case Operation::StrokeArcOperation: + case Operation::StrokePathOperation: + case Operation::StrokeRectOperation: + case Operation::DrawComplexTextOperation: + case Operation::DrawTextOperation: + return true; + default: + return false; + } +} + GraphicsOperationCollection::GraphicsOperationCollection() { } @@ -23,20 +48,51 @@ GraphicsOperationCollection::~GraphicsOperationCollection() void GraphicsOperationCollection::apply(PlatformGraphicsContext* context) { + flush(); for (unsigned int i = 0; i < m_operations.size(); i++) m_operations[i]->apply(context); } -void GraphicsOperationCollection::adoptAndAppend(GraphicsOperation::Operation* operation) +void GraphicsOperationCollection::adoptAndAppend(GraphicsOperation::Operation* rawOp) { - m_operations.append(adoptRef(operation)); + PassRefPtr operation = adoptRef(rawOp); + if (operation->type() == Operation::SaveOperation) { + // TODO: Support nested Save/Restore checking? + flush(); + m_pendingOperations.append(operation); + return; + } + if (m_pendingOperations.size()) { + if (operation->type() == Operation::RestoreOperation) { + // We hit a Save/Restore pair without any drawing, discard + m_pendingOperations.clear(); + return; + } + if (!isDrawingOperation(operation.get())) { + // Isn't a drawing operation, so append to pending and return + m_pendingOperations.append(operation); + return; + } + // Hit a drawing operation, so flush the pending and append to m_operations + flush(); + } + m_operations.append(operation); } bool GraphicsOperationCollection::isEmpty() { + flush(); return !m_operations.size(); } +void GraphicsOperationCollection::flush() +{ + if (m_pendingOperations.size()) { + m_operations.append(m_pendingOperations); + m_pendingOperations.clear(); + } +} + } // namespace WebCore #endif // USE(ACCELERATED_COMPOSITING) diff --git a/Source/WebCore/platform/graphics/android/context/GraphicsOperationCollection.h b/Source/WebCore/platform/graphics/android/context/GraphicsOperationCollection.h index 246e784..e7e4ccc 100644 --- a/Source/WebCore/platform/graphics/android/context/GraphicsOperationCollection.h +++ b/Source/WebCore/platform/graphics/android/context/GraphicsOperationCollection.h @@ -48,6 +48,9 @@ public: bool isEmpty(); private: + void flush(); + + Vector< RefPtr > m_pendingOperations; Vector< RefPtr > m_operations; }; -- cgit v1.1