Revert of Avoid redundant initialization of GraphicsContextState....

Revert of Avoid redundant initialization of GraphicsContextState. (https://codereview.chromium.org/303613002/)

Reason for revert:
This change is the cause of a
leak in PhishingDOMFeatureExtractorTest.ScriptAndImageFeatures
under LSAN. See
http://build.chromium.org/p/chromium.memory/builders/Linux%20ASan%20LSan%20Tests%20%281%29/builds/2642/steps/browser_tests/logs/ScriptAndImageFeatures

Original issue's description:
> 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

TBR=schenney@chromium.org,fmalita@chromium.org,dominikg@chromium.org
NOTREECHECKS=true
NOTRY=true
BUG=377687

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

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