Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1176)

Unified Diff: Source/core/platform/graphics/GraphicsContext.cpp

Issue 18551004: Miscellaneous cleanup to reduce number of includes in platform/graphics/ Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/core/platform/graphics/GraphicsContext.cpp
diff --git a/Source/core/platform/graphics/GraphicsContext.cpp b/Source/core/platform/graphics/GraphicsContext.cpp
index 63ca4a9e79f2705466185285b06b0a836ccd666b..3361cd72bb5ab60bc0a2349e03aea5bbf0bece91 100644
--- a/Source/core/platform/graphics/GraphicsContext.cpp
+++ b/Source/core/platform/graphics/GraphicsContext.cpp
@@ -27,16 +27,23 @@
#include "config.h"
#include "core/platform/graphics/GraphicsContext.h"
+#include "core/platform/chromium/TraceEvent.h"
#include "core/platform/graphics/BitmapImage.h"
+#include "core/platform/graphics/Font.h"
#include "core/platform/graphics/Gradient.h"
+#include "core/platform/graphics/GraphicsContextAnnotation.h"
#include "core/platform/graphics/ImageBuffer.h"
#include "core/platform/graphics/IntRect.h"
+#include "core/platform/graphics/Path.h"
+#include "core/platform/graphics/Pattern.h"
#include "core/platform/graphics/RoundedRect.h"
+#include "core/platform/graphics/TextRun.h"
#include "core/platform/graphics/TextRunIterator.h"
#include "core/platform/graphics/skia/SkiaUtils.h"
#include "core/platform/text/BidiResolver.h"
#include "third_party/skia/include/core/SkAnnotation.h"
#include "third_party/skia/include/core/SkColorFilter.h"
+#include "third_party/skia/include/core/SkColorPriv.h"
#include "third_party/skia/include/core/SkData.h"
#include "third_party/skia/include/core/SkDevice.h"
#include "third_party/skia/include/core/SkRRect.h"
@@ -55,6 +62,20 @@ using namespace std;
namespace WebCore {
+// Helper function for applying the state's alpha value to the given input
+// color to produce a new output color.
+static SkColor applyAlpha(SkColor c, float alpha)
+{
+ int s = roundf(alpha * 256);
+ if (s >= 256)
+ return c;
+ if (s < 0)
+ return 0;
+
+ int a = SkAlphaMul(SkColorGetA(c), s);
+ return (c & 0x00FFFFFF) | (a << 24);
+}
+
struct GraphicsContext::DeferredSaveState {
DeferredSaveState(unsigned mask, int count) : m_flags(mask), m_restoreCount(count) { }
@@ -200,11 +221,9 @@ void GraphicsContext::endAnnotation()
#endif
}
-void GraphicsContext::setStrokeColor(const Color& color)
+SkColor GraphicsContext::effectiveStrokeColor() const
{
- m_state->m_strokeData.setColor(color);
- m_state->m_strokeData.clearGradient();
- m_state->m_strokeData.clearPattern();
+ return applyAlpha(m_state->m_strokeData.color().rgb(), m_state->m_alpha);
}
void GraphicsContext::setStrokePattern(PassRefPtr<Pattern> pattern)
@@ -217,7 +236,6 @@ void GraphicsContext::setStrokePattern(PassRefPtr<Pattern> pattern)
setStrokeColor(Color::black);
return;
}
- m_state->m_strokeData.clearGradient();
m_state->m_strokeData.setPattern(pattern);
}
@@ -232,7 +250,6 @@ void GraphicsContext::setStrokeGradient(PassRefPtr<Gradient> gradient)
return;
}
m_state->m_strokeData.setGradient(gradient);
- m_state->m_strokeData.clearPattern();
}
void GraphicsContext::setFillColor(const Color& color)
@@ -242,6 +259,11 @@ void GraphicsContext::setFillColor(const Color& color)
m_state->m_fillPattern.clear();
}
+SkColor GraphicsContext::effectiveFillColor() const
+{
+ return applyAlpha(m_state->m_fillColor.rgb(), m_state->m_alpha);
+}
+
void GraphicsContext::setFillPattern(PassRefPtr<Pattern> pattern)
{
if (paintingDisabled())
@@ -378,24 +400,22 @@ bool GraphicsContext::readPixels(SkBitmap* bitmap, int x, int y, SkCanvas::Confi
return m_canvas->readPixels(bitmap, x, y, config8888);
}
-void GraphicsContext::setMatrix(const SkMatrix& matrix)
+void GraphicsContext::setCTM(const AffineTransform& transform)
{
if (paintingDisabled())
return;
realizeSave(SkCanvas::kMatrix_SaveFlag);
-
- m_canvas->setMatrix(matrix);
+ m_canvas->setMatrix(transform);
}
-bool GraphicsContext::concat(const SkMatrix& matrix)
+void GraphicsContext::concatCTM(const AffineTransform& transform)
{
if (paintingDisabled())
- return false;
+ return;
realizeSave(SkCanvas::kMatrix_SaveFlag);
-
- return m_canvas->concat(matrix);
+ m_canvas->concat(transform);
}
void GraphicsContext::beginTransparencyLayer(float opacity)
@@ -921,7 +941,7 @@ void GraphicsContext::drawEmphasisMarks(const Font& font, const TextRunPaintInfo
font.drawEmphasisMarks(this, runInfo, mark, point);
}
-void GraphicsContext::drawBidiText(const Font& font, const TextRunPaintInfo& runInfo, const FloatPoint& point, Font::CustomFontNotReadyAction customFontNotReadyAction)
+void GraphicsContext::drawBidiText(const Font& font, const TextRunPaintInfo& runInfo, const FloatPoint& point, CustomFontNotReadyAction customFontNotReadyAction)
{
if (paintingDisabled())
return;
@@ -1872,7 +1892,7 @@ void GraphicsContext::setupShader(SkPaint* paint, Gradient* grad, Pattern* pat,
paint->setFilterBitmap(imageInterpolationQuality() != InterpolationNone);
}
- paint->setColor(m_state->applyAlpha(color));
+ paint->setColor(applyAlpha(color, m_state->m_alpha));
paint->setShader(shader);
}
« no previous file with comments | « Source/core/platform/graphics/GraphicsContext.h ('k') | Source/core/platform/graphics/GraphicsContextAnnotation.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698