Commit c876c9f3 authored by dominikg@chromium.org's avatar dominikg@chromium.org

Avoid redundant initialization of GraphicsContextState.

When creating a new GraphicsContextState the constructor initializes the state
with various default values. In GraphicsContext::realizePaintState we immediately
overwrite these values after creation. This patch adds a copy constructor to
GraphicsContextState to avoid that.

Even though this seems like a clear win, the benefits are not visible when
profiling. Looks like the overhead of the redundant initialization is
not very large. Still seems worth fixing though.

BUG=377687

Committed: https://src.chromium.org/viewvc/blink?view=rev&revision=174985

Review URL: https://codereview.chromium.org/303613002

git-svn-id: svn://svn.chromium.org/blink/trunk@175894 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 3396cb8b
......@@ -463,11 +463,14 @@ private:
if (m_paintState->saveCount()) {
m_paintState->decrementSaveCount();
++m_paintStateIndex;
if (m_paintStateStack.size() == m_paintStateIndex)
m_paintStateStack.append(GraphicsContextState::create());
GraphicsContextState* priorPaintState = m_paintState;
m_paintState = m_paintStateStack[m_paintStateIndex].get();
m_paintState->copy(priorPaintState);
if (m_paintStateStack.size() == m_paintStateIndex) {
m_paintStateStack.append(GraphicsContextState::createAndCopy(*m_paintState));
m_paintState = m_paintStateStack[m_paintStateIndex].get();
} else {
GraphicsContextState* priorPaintState = m_paintState;
m_paintState = m_paintStateStack[m_paintStateIndex].get();
m_paintState->copy(*priorPaintState);
}
}
}
......
......@@ -36,27 +36,30 @@ GraphicsContextState::GraphicsContextState()
m_fillPaint.setAntiAlias(m_shouldAntialias);
}
void GraphicsContextState::copy(GraphicsContextState* source)
{
m_strokePaint = source->m_strokePaint;
m_fillPaint = source->m_fillPaint;
m_strokeData = source->m_strokeData;
m_fillColor = source->m_fillColor;
m_fillRule = source->m_fillRule;
m_fillGradient = source->m_fillGradient;
m_fillPattern = source->m_fillPattern;
m_looper = source->m_looper;
m_textDrawingMode = source->m_textDrawingMode;
m_alpha = source->m_alpha;
m_xferMode = source->m_xferMode;
m_colorFilter = source->m_colorFilter;
m_compositeOperator = source->m_compositeOperator;
m_blendMode = source->m_blendMode;
m_interpolationQuality = source->m_interpolationQuality;
m_saveCount = 0;
m_shouldAntialias = source->m_shouldAntialias;
m_shouldSmoothFonts = source->m_shouldSmoothFonts;
m_shouldClampToSourceRect = source->m_shouldClampToSourceRect;
GraphicsContextState::GraphicsContextState(const GraphicsContextState& other)
: m_strokePaint(other.m_strokePaint)
, m_fillPaint(other.m_fillPaint)
, m_strokeData(other.m_strokeData)
, m_fillColor(other.m_fillColor)
, m_fillRule(other.m_fillRule)
, m_fillGradient(other.m_fillGradient)
, m_fillPattern(other.m_fillPattern)
, m_looper(other.m_looper)
, m_textDrawingMode(other.m_textDrawingMode)
, m_alpha(other.m_alpha)
, m_xferMode(other.m_xferMode)
, m_colorFilter(other.m_colorFilter)
, m_compositeOperator(other.m_compositeOperator)
, m_blendMode(other.m_blendMode)
, m_interpolationQuality(other.m_interpolationQuality)
, m_saveCount(0)
, m_shouldAntialias(other.m_shouldAntialias)
, m_shouldSmoothFonts(other.m_shouldSmoothFonts)
, m_shouldClampToSourceRect(other.m_shouldClampToSourceRect) { }
void GraphicsContextState::copy(const GraphicsContextState& source)
{
new (this) GraphicsContextState(source);
}
const SkPaint& GraphicsContextState::strokePaint(int strokedPathLength) const
......
......@@ -46,14 +46,18 @@ namespace WebCore {
// Encapsulates the state information we store for each pushed graphics state.
// Only GraphicsContext can use this class.
class PLATFORM_EXPORT GraphicsContextState FINAL {
WTF_MAKE_NONCOPYABLE(GraphicsContextState);
public:
static PassOwnPtr<GraphicsContextState> create()
{
return adoptPtr(new GraphicsContextState());
}
void copy(GraphicsContextState*);
static PassOwnPtr<GraphicsContextState> createAndCopy(const GraphicsContextState& other)
{
return adoptPtr(new GraphicsContextState(other));
}
void copy(const GraphicsContextState&);
// SkPaint objects that reflect the current state. If the length of the
// path to be stroked is known, pass it in for correct dash or dot placement.
......@@ -142,6 +146,8 @@ public:
private:
GraphicsContextState();
explicit GraphicsContextState(const GraphicsContextState&);
GraphicsContextState& operator=(const GraphicsContextState&);
// Helper function for applying the state's alpha value to the given input
// color to produce a new output color.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment