Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / platform / graphics / GraphicsContextState.cpp
index abd3c18..657d0df 100644 (file)
@@ -5,62 +5,68 @@
 #include "config.h"
 #include "platform/graphics/GraphicsContextState.h"
 
-namespace WebCore {
+#include "platform/graphics/skia/SkiaUtils.h"
+
+namespace blink {
 
 GraphicsContextState::GraphicsContextState()
-    : m_fillColor(Color::black)
+    : m_strokeColor(Color::black)
+    , m_fillColor(Color::black)
     , m_fillRule(RULE_NONZERO)
     , m_textDrawingMode(TextModeFill)
     , m_alpha(256)
-    , m_xferMode(nullptr)
     , m_compositeOperator(CompositeSourceOver)
-    , m_blendMode(blink::WebBlendModeNormal)
+    , m_blendMode(WebBlendModeNormal)
     , m_interpolationQuality(InterpolationDefault)
     , m_saveCount(0)
     , m_shouldAntialias(true)
-    , m_shouldSmoothFonts(true)
     , m_shouldClampToSourceRect(true)
 {
     m_strokePaint.setStyle(SkPaint::kStroke_Style);
     m_strokePaint.setStrokeWidth(SkFloatToScalar(m_strokeData.thickness()));
-    m_strokePaint.setColor(applyAlpha(m_strokeData.color().rgb()));
+    m_strokePaint.setColor(applyAlpha(m_strokeColor.rgb()));
     m_strokePaint.setStrokeCap(SkPaint::kDefault_Cap);
     m_strokePaint.setStrokeJoin(SkPaint::kDefault_Join);
     m_strokePaint.setStrokeMiter(SkFloatToScalar(m_strokeData.miterLimit()));
-    m_strokePaint.setFilterBitmap(m_interpolationQuality != InterpolationNone);
+    m_strokePaint.setFilterLevel(WebCoreInterpolationQualityToSkFilterLevel(m_interpolationQuality));
     m_strokePaint.setAntiAlias(m_shouldAntialias);
     m_fillPaint.setColor(applyAlpha(m_fillColor.rgb()));
-    m_fillPaint.setFilterBitmap(m_interpolationQuality != InterpolationNone);
+    m_fillPaint.setFilterLevel(WebCoreInterpolationQualityToSkFilterLevel(m_interpolationQuality));
     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_strokeColor(other.m_strokeColor)
+    , m_strokeGradient(other.m_strokeGradient)
+    , m_strokePattern(other.m_strokePattern)
+    , 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_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_shouldClampToSourceRect(other.m_shouldClampToSourceRect) { }
+
+void GraphicsContextState::copy(const GraphicsContextState& source)
+{
+    this->~GraphicsContextState();
+    new (this) GraphicsContextState(source);
 }
 
 const SkPaint& GraphicsContextState::strokePaint(int strokedPathLength) const
 {
-    if (m_strokeData.gradient() && m_strokeData.gradient()->shaderChanged())
-        m_strokePaint.setShader(m_strokeData.gradient()->shader());
+    if (m_strokeGradient && m_strokeGradient->shaderChanged())
+        m_strokePaint.setShader(m_strokeGradient->shader());
     m_strokeData.setupPaintDashPathEffect(&m_strokePaint, strokedPathLength);
     return m_strokePaint;
 }
@@ -85,43 +91,43 @@ void GraphicsContextState::setStrokeThickness(float thickness)
 
 void GraphicsContextState::setStrokeColor(const Color& color)
 {
-    m_strokeData.clearGradient();
-    m_strokeData.clearPattern();
-    m_strokeData.setColor(color);
+    m_strokeGradient.clear();
+    m_strokePattern.clear();
+    m_strokeColor = color;
     m_strokePaint.setColor(applyAlpha(color.rgb()));
     m_strokePaint.setShader(0);
 }
 
 void GraphicsContextState::setStrokeGradient(const PassRefPtr<Gradient> gradient)
 {
-    m_strokeData.setColor(Color::black);
-    m_strokeData.clearPattern();
-    m_strokeData.setGradient(gradient);
+    m_strokeColor = Color::black;
+    m_strokePattern.clear();
+    m_strokeGradient = gradient;
     m_strokePaint.setColor(applyAlpha(SK_ColorBLACK));
-    m_strokePaint.setShader(m_strokeData.gradient()->shader());
+    m_strokePaint.setShader(m_strokeGradient->shader());
 }
 
 void GraphicsContextState::clearStrokeGradient()
 {
-    m_strokeData.clearGradient();
-    ASSERT(!m_strokeData.pattern());
-    m_strokePaint.setColor(applyAlpha(m_strokeData.color().rgb()));
+    m_strokeGradient.clear();
+    ASSERT(!m_strokePattern);
+    m_strokePaint.setColor(applyAlpha(m_strokeColor.rgb()));
 }
 
 void GraphicsContextState::setStrokePattern(const PassRefPtr<Pattern> pattern)
 {
-    m_strokeData.setColor(Color::black);
-    m_strokeData.clearGradient();
-    m_strokeData.setPattern(pattern);
+    m_strokeColor = Color::black;
+    m_strokeGradient.clear();
+    m_strokePattern = pattern;
     m_strokePaint.setColor(applyAlpha(SK_ColorBLACK));
-    m_strokePaint.setShader(m_strokeData.pattern()->shader());
+    m_strokePaint.setShader(m_strokePattern->shader());
 }
 
 void GraphicsContextState::clearStrokePattern()
 {
-    m_strokeData.clearPattern();
-    ASSERT(!m_strokeData.gradient());
-    m_strokePaint.setColor(applyAlpha(m_strokeData.color().rgb()));
+    m_strokePattern.clear();
+    ASSERT(!m_strokeGradient);
+    m_strokePaint.setColor(applyAlpha(m_strokeColor.rgb()));
 }
 
 void GraphicsContextState::setLineCap(LineCap cap)
@@ -207,7 +213,7 @@ void GraphicsContextState::setAlphaAsFloat(float alpha)
         if (m_alpha > 256)
             m_alpha = 256;
     }
-    m_strokePaint.setColor(applyAlpha(m_strokeData.color().rgb()));
+    m_strokePaint.setColor(applyAlpha(m_strokeColor.rgb()));
     m_fillPaint.setColor(applyAlpha(m_fillColor.rgb()));
 }
 
@@ -223,20 +229,20 @@ void GraphicsContextState::setColorFilter(PassRefPtr<SkColorFilter> colorFilter)
     m_fillPaint.setColorFilter(m_colorFilter.get());
 }
 
-void GraphicsContextState::setCompositeOperation(CompositeOperator compositeOperation, blink::WebBlendMode blendMode)
+void GraphicsContextState::setCompositeOperation(CompositeOperator compositeOperation, WebBlendMode blendMode)
 {
     m_compositeOperator = compositeOperation;
     m_blendMode = blendMode;
-    m_xferMode = WebCoreCompositeToSkiaComposite(compositeOperation, blendMode);
-    m_strokePaint.setXfermode(m_xferMode.get());
-    m_fillPaint.setXfermode(m_xferMode.get());
+    SkXfermode::Mode xferMode = WebCoreCompositeToSkiaComposite(compositeOperation, blendMode);
+    m_strokePaint.setXfermodeMode(xferMode);
+    m_fillPaint.setXfermodeMode(xferMode);
 }
 
 void GraphicsContextState::setInterpolationQuality(InterpolationQuality quality)
 {
     m_interpolationQuality = quality;
-    m_strokePaint.setFilterBitmap(quality != InterpolationNone);
-    m_fillPaint.setFilterBitmap(quality != InterpolationNone);
+    m_strokePaint.setFilterLevel(WebCoreInterpolationQualityToSkFilterLevel(quality));
+    m_fillPaint.setFilterLevel(WebCoreInterpolationQualityToSkFilterLevel(quality));
 }
 
 void GraphicsContextState::setShouldAntialias(bool shouldAntialias)
@@ -247,4 +253,4 @@ void GraphicsContextState::setShouldAntialias(bool shouldAntialias)
 }
 
 
-} // namespace WebCore
+} // namespace blink